public IHttpActionResult AddDeal(Deal deal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repository.Add(deal); return(CreatedAtRoute("DefaultApi", new { id = deal.DealId }, deal)); }
public async Task <DealModel> CreateDeal(DealModel model) { model.ID = Guid.NewGuid(); var result = await _repo.Add(model); result = await this.UpdateDealImage(result, model); return(result); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,Duration,StartDate,BusinessId,Active,Category")] Deal deal) { if (ModelState.IsValid) { await _dealRepository.Add(deal); return(RedirectToAction(nameof(Index), new { id = deal.BusinessId })); } ViewData["BusinessId"] = deal.BusinessId; return(View(deal)); }
public HttpResponseMessage CreateDeal(DealModel dealModel) { ResponseModel _response = new ResponseModel(); var model = Mapper.Map <DealModel, Deal>(dealModel); model.CreatedDate = DateTime.Now; model.Status = (int)Status.Created; model.IsDeleted = false; _dealRepository.Add(model); int Rows = _dealRepository.SaveChanges(); if (Rows > 0) { if (dealModel.lstSchemes != null && dealModel.lstSchemes.Count > 0) { // Scheme not mandatory List <Scheme> schemes = new List <Scheme>(); foreach (var item in dealModel.lstSchemes) { Scheme objScheme = new Scheme(); objScheme.DealId = model.DealId; objScheme.SchemeTypeId = item.SchemeTypeId; objScheme.MinOrderQuantity = item.MinOrderQuantity; objScheme.DealRate = item.DealRate; objScheme.Saving = item.Saving; objScheme.DealScheme = item.DealScheme; objScheme.Status = (int)Status.Created; objScheme.IsDeleted = false; objScheme.CreatedBy = item.CreatedBy; objScheme.CreatedDate = DateTime.Now; schemes.Add(objScheme); } _schemeRepository.SaveList(schemes); _schemeRepository.SaveChanges(); } // For Uploading image ---- if (dealModel.DocProduct != null) { UploadDocumentModel UploadDocument = new UploadDocumentModel(); UploadDocument.documents = new List <DocumentModel>(); UploadDocument.ImageSize = 250; UploadDocument.ImageQuality = 250; UploadDocument.documents.Add(dealModel.DocProduct); List <string> uploadedFileName = SavePicture(UploadDocument); if (uploadedFileName.Count > 0) { Deal _deal = _dealRepository.FindBy(x => x.DealId == model.DealId).FirstOrDefault(); if (_deal != null) { _deal.ProductImagePath = uploadedFileName[0].ToString(); _dealRepository.Update(_deal); _dealRepository.SaveChanges(); } } } _response.Type = "success"; _response.Message = "Scheme added successfully"; return(Request.CreateResponse(HttpStatusCode.OK, _response)); } else { _response.Type = "error"; _response.Message = "Something went wrong"; return(Request.CreateResponse(HttpStatusCode.OK, _response)); } }