Пример #1
0
func (p *Price) Delete() error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(deletePrice)
	_, err = stmt.Exec(p.ID)
	if err != nil {
		tx.Rollback()
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	go redis.Delete("price:" + strconv.Itoa(p.ID))
	go redis.Delete(fmt.Sprintf("prices:part:%d", strconv.Itoa(p.PartID)))
	go redis.Delete(fmt.Sprintf("customers:prices:%d", strconv.Itoa(p.CustID)))
	return nil
}
Пример #2
0
// Creates a WebPropertyRequirement
func (r *WebPropertyRequirement) Create(dtx *apicontext.DataContext) error {
	go redis.Delete("webpropertyrequirements:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(createRequirement)
	res, err := stmt.Exec(r.ReqType, r.Requirement)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()

	r.RequirementID = int(id)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()

	return nil
}
Пример #3
0
// Creates a new note for a web property.
func (n *WebPropertyNote) Create(dtx *apicontext.DataContext) error {
	go redis.Delete("webpropertynotes:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(createNote)
	da := time.Now()
	n.DateAdded = &da
	res, err := stmt.Exec(n.WebPropID, n.Text, n.DateAdded)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	n.ID = int(id)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()

	return nil
}
Пример #4
0
// Creates a Web Property
func (w *WebProperty) Create(dtx *apicontext.DataContext) (err error) {
	go redis.Delete("webproperties:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(create)
	add := time.Now()
	w.AddedDate = &add
	res, err := stmt.Exec(
		w.Name,
		w.CustID,
		w.Url,
		w.IsEnabled,
		w.SellerID,
		w.WebPropertyType.ID,
		w.IsFinalApproved,
		w.IsEnabledDate,
		w.IsDenied,
		w.RequestedDate,
		w.AddedDate,
	)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	w.ID = int(id)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()

	//create/update web properties check
	for _, req := range w.WebPropertyRequirements {
		req.WebPropID = w.ID

		err = req.CreateJoin()
		if err != nil {
			return err
		}
	}
	//create/updated notes
	for _, note := range w.WebPropertyNotes {
		note.WebPropID = w.ID

		err = note.Create(dtx)
		if err != nil {
			return err
		}
	}

	return nil
}
Пример #5
0
// creates a WebPropertyType
func (t *WebPropertyType) Create(dtx *apicontext.DataContext) error {
	go redis.Delete("webpropertytypes:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(createType)
	res, err := stmt.Exec(t.TypeID, t.Type)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	if err != nil {
		return err
	}
	t.ID = int(id)
	tx.Commit()
	return nil
}
Пример #6
0
// Deletes a Web Property Requirement
func (r *WebPropertyRequirement) Delete(dtx *apicontext.DataContext) error {
	go redis.Delete("webpropertyrequirements:" + dtx.BrandString)
	var err error
	err = r.Get()
	if err != nil {
		return err
	}
	err = r.DeleteJoinByRequirementId()
	if err != nil {
		return err
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(deleteRequirement)
	_, err = stmt.Exec(r.RequirementID)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()
	// r.DeleteJoin()

	return nil
}
Пример #7
0
func (p *Price) Create() error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}

	stmt, err := tx.Prepare(createPrice)
	res, err := stmt.Exec(p.CustID, p.PartID, p.Price, p.IsSale, p.SaleStart, p.SaleEnd)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	p.ID = int(id)
	if err != nil {
		tx.Rollback()
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	go redis.Delete(allPricesRedisKey)
	go redis.Setex("price:"+strconv.Itoa(p.ID), p, 86400)
	return nil
}
Пример #8
0
func (l *CustomerLocation) Create(dtx *apicontext.DataContext) error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(createLocation)
	if err != nil {
		return err
	}

	res, err := stmt.Exec(
		l.Name,
		l.Address,
		l.City,
		l.State.Id,
		l.Email,
		l.Phone,
		l.Fax,
		l.Coordinates.Latitude,
		l.Coordinates.Longitude,
		l.CustomerId,
		l.ContactPerson,
		l.IsPrimary,
		l.PostalCode,
		l.ShippingDefault,
	)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	l.Id = int(id)
	if err != nil {
		return err
	}
	err = tx.Commit()
	go redis.Delete("customers:locations:" + dtx.BrandString)
	go redis.Delete("customerLocations:" + strconv.Itoa(l.CustomerId))
	return err
}
Пример #9
0
func (l *CustomerLocation) Delete(dtx *apicontext.DataContext) error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(deleteLocation)
	if err != nil {
		return err
	}
	_, err = stmt.Exec(l.Id)
	if err != nil {
		tx.Rollback()
		return err
	}
	err = tx.Commit()
	go redis.Delete("customers:locations:" + dtx.BrandString)
	go redis.Delete("customerLocations:" + strconv.Itoa(l.CustomerId))
	return err
}
Пример #10
0
func (p *PartVideo) DeleteByPart(dtx *apicontext.DataContext) (err error) {
	go redis.Delete(fmt.Sprintf("part:%d:videos:%s", p.PartID, dtx.BrandString))
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	stmt, err := db.Prepare(deletePartVideos)
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(p.PartID)
	if err != nil {
		return err
	}
	return nil
}
Пример #11
0
// Deletes all of the notes of a specific Web Property
func (n *WebProperty) DeleteNotesByPropId(dtx *apicontext.DataContext) error {
	go redis.Delete("webpropertynotes:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(deletePropertyNotes)
	_, err = stmt.Exec(n.ID)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()

	return nil
}
Пример #12
0
// Deletes a Web Property and any associations.
func (w *WebProperty) Delete(dtx *apicontext.DataContext) error {
	go redis.Delete("webproperties:" + dtx.BrandString)
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()

	notesChan := make(chan int)
	requirementsChan := make(chan int)

	go func() {
		err = w.DeleteNotesByPropId(dtx)
		notesChan <- 1
	}()
	go func() {
		err = w.DeleteJoinByPropId()
		requirementsChan <- 1
	}()
	<-notesChan
	<-requirementsChan

	tx, err := db.Begin()
	if err != nil {
		return err
	}

	stmt, err := tx.Prepare(deleteWebProp)
	_, err = stmt.Exec(w.ID)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()

	return nil
}
Пример #13
0
func (p *PartVideo) CreatePartVideo(dtx *apicontext.DataContext) (err error) {
	go redis.Delete(fmt.Sprintf("part:%d:videos:%s", p.PartID, dtx.BrandString))
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	stmt, err := db.Prepare(createPartVideo)
	if err != nil {
		return err
	}
	defer stmt.Close()
	res, err := stmt.Exec(p.PartID, p.YouTubeVideoId, p.VideoType.ID, p.IsPrimary)
	if err != nil {
		return err
	}
	id, err := res.LastInsertId()
	if err != nil {
		return err
	}

	p.ID = int(id)
	return nil
}