/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public TenderJsonModel(Tender tender) { Id = tender.Id; UserId = tender.UserId; CategoryId = tender.CategoryId; CategoryName = tender.Category != null ? tender.Category.Title : ""; Title = tender.Title; Description = tender.Description; MinPrice = tender.MinPrice.ToString("0"); MaxPrice = tender.MaxPrice.ToString("0"); Currency = tender.Currency; Size = tender.Size; Measure = tender.Measure; DateStart = tender.DateStart; DateEnd = tender.DateEnd; Period = tender.Period; Image = tender.Image; Keywords = tender.Keywords; DateCreated = tender.DateCreated; }
/// <summary> /// Обновляет содержимое тендера из модели /// </summary> /// <param name="tender"></param> public void UpdateTender(Tender tender) { tender.Title = this.Title; tender.Description = this.Description; tender.MinPrice = Convert.ToDecimal(this.MinPrice); tender.MaxPrice = Convert.ToDecimal(this.MaxPrice); tender.Currency = this.Currency; tender.Size = this.Size; tender.Measure = this.Measure; tender.DateStart = this.DateStart; tender.DateEnd = this.DateEnd; tender.Period = this.Period; tender.Image = this.Image; tender.Keywords = this.Keywords; if (this.CategoryId != tender.CategoryId) { tender.Category = Locator.GetService<ICategoriesRepository>().Load(this.CategoryId); } if (this.UserId != tender.UserId) { tender.User = Locator.GetService<IUsersRepository>().Load(this.UserId); } }
public ActionResult SaveTender(Tender model) { if (!IsAuthentificated) { return RedirectToAction("Register"); } // Сохраняем или создание Tender tender = null; if (model.Id <= 0) { tender = model; tender.DateCreated = DateTime.Now; // TODO: добавить сохранение фотографий по тендерам CurrentUser.Tenders.Add(tender); } else { tender = CurrentUser.Tenders.First(t => t.Id == model.Id); tender.Title = model.Title; tender.Keywords = model.Keywords; tender.Description = model.Description; tender.MinPrice = model.MinPrice; tender.MaxPrice = model.MaxPrice; tender.Category = Locator.GetService<ICategoriesRepository>().Load(model.CategoryId); tender.Measure = model.Measure; tender.Size = model.Size; tender.Currency = model.Currency; tender.DateStart = model.DateStart; tender.DateEnd = model.DateEnd; } UsersRepository.SubmitChanges(); // Сохраняем фото к тендеру var tenderImageFile = Request.Files["TenderImage"]; if (tenderImageFile != null && tenderImageFile.ContentLength > 0 && tenderImageFile.ContentType.Contains("image")) { var fileName = String.Format("tender-{0}-{1}{2}", tender.Id, new Random(System.Environment.TickCount).Next(Int32.MaxValue), Path.GetExtension(tenderImageFile.FileName)); FileUtils.SavePostedFile(tenderImageFile, "tenderimage", fileName); tender.Image = fileName; UsersRepository.SubmitChanges(); } // Перенаправляемся на список тендеров return RedirectToAction("Tenders"); }
public ActionResult SaveTender(TenderJsonModel model) { var rep = Locator.GetService<ITendersRepository>(); try { if (model.Id <= 0) { var newTender = new Tender() { DateCreated = DateTime.Now }; model.UpdateTender(newTender); rep.Add(newTender); rep.SubmitChanges(); } else { var tender = rep.Load(model.Id); model.UpdateTender(tender); rep.SubmitChanges(); } return JsonSuccess(); } catch (Exception e) { return JsonErrors(e.Message); } }
private void detach_Tenders(Tender entity) { this.SendPropertyChanging(); entity.Category = null; }
private void attach_Tenders(Tender entity) { this.SendPropertyChanging(); entity.Category = this; }