public IHttpActionResult AddLineItem(long expectedReceiptLineId, ItemBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } long retId; try { retId = _expectedReceiptLineService.AddLineItem(model, expectedReceiptLineId); Log.Info($"{typeof(ExpectedReceiptController).FullName}||{UserEnvironment}||Add record successful."); } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, ex.Message)); } var response = this.Request.CreateResponse(HttpStatusCode.Created); string test = JsonConvert.SerializeObject(new { id = retId, message = "Expected Receipt added" }); response.Content = new StringContent(test, Encoding.UTF8, "appliation/json"); return(ResponseMessage(response)); }
public async Task <bool> CreateItemAsync(ItemBindingModel model) { if (model.Price <= 0 || string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Description) || model.ImgUrl == null) { return(false); } var item = this.mapper.Map <Item>(model); var url = MyCloudinary.UploadImage(model.ImgUrl, model.Name); item.ImgUrl = url ?? Constants.CloudinaryInvalidUrl; var category = this.context.ChildCategories.FirstOrDefault(cat => cat.Name == model.CategoryName.ToString()); var supplier = this.context.Suppliers.FirstOrDefault(sup => sup.Name == model.SupplierName); item.ItemCategories.Add(new ItemCategory { ChildCategoryId = category.Id }); item.Supplier = supplier; await this.context.Items.AddAsync(item); await this.context.SaveChangesAsync(); return(this.context.Items.Contains(item)); }
public static Item ToItem(this ItemBindingModel model, CategoryRepository categoryRepo) { var cat1 = categoryRepo.FindOrCreate(model.Category1); var cat2 = categoryRepo.FindOrCreate(model.Category2); var cat3 = categoryRepo.FindOrCreate(model.Category3); var fileMeta = FileHelpers.GetMp3Meta(model.File); var fileURL = new FTPClient().UploadFile(model.File); return(new Item() { Author = model.Author, Category2 = cat2, Category3 = cat3, ChannelID = model.ChannelID, Description = model.Description, FileSizeInBytes = fileMeta.FileSizeInBytes, FileURL = fileURL, ID = model.ID, IsExplicit = model.IsExplicit, Keywords = model.Keywords, LengthInSeconds = fileMeta.LengthInSeconds, MimeType = fileMeta.MimeType, PrimaryCategory = cat1, PublicationDate = model.PublicationDate, SubTitle = model.SubTitle, Summary = model.Description, Title = model.Title, URL = model.URL }); }
public ActionResult Edit(ItemBindingModel model) { if (ModelState.IsValid) { var item = model.ToItem(catRepo); repo.Update(item); return(RedirectToAction("Index", new { channelId = model.ChannelID })); } return(View(model)); }
public async Task <IActionResult> CreateItem(ItemBindingModel model) { if (!this.ModelState.IsValid) { return(this.View("AddItem", model)); } await this.shopService.CreateItemAsync(model); return(this.View("Success")); }
public IHttpActionResult UpdateItem([FromUri] int id, [FromBody] ItemBindingModel model) { Exception ex = null; try { var item = model.GetEntity(); _dataProvider.SaveEntity <Item>(item); } catch (Exception e) { ex = e; } return(GetHttpActionResult(ex)); }
public IActionResult AddItem( [FromRoute] string database, [FromBody] ItemBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Item item = new Item { Title = model.Title, Description = model.Description, FacetId = model.FacetId, SortKey = model.SortKey, Flags = model.Flags, // override the user ID UserId = User.Identity.Name, }; // set the creator ID if not specified if (string.IsNullOrEmpty(item.CreatorId)) { item.CreatorId = User.Identity.Name; } // set the item's ID if specified, else go with the default // newly generated one if (!string.IsNullOrEmpty(model.Id) && _guidRegex.IsMatch(model.Id)) { item.Id = model.Id; } _logger.Information("User {UserName} saving item {ItemId} from {IP}", User.Identity.Name, item.Id, HttpContext.Connection.RemoteIpAddress); ICadmusRepository repository = _repositoryProvider.CreateRepository(database); repository.AddItem(item); return(CreatedAtRoute("GetItem", new { database, id = item.Id, parts = false }, item)); }
public ActionResult Create(ItemBindingModel model) { if (ModelState.IsValid) { var item = model.ToItem(catRepo); item.PublicationDate = DateTime.Now; repo.Create(item); return(RedirectToAction("Index", new { channelId = model.ChannelID })); } string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); return(View(model)); }
public long AddLineItem(ItemBindingModel model, long expectedReceiptLineId) { Expression <Func <Product, bool> > res = x => x.ProductCode.ToLower() == model.ProductCode.ToLower(); var product = _productService.GetByProductCode(model.ProductCode); var brand = _brandService.GetByBrandCode(model.BrandCode); var warehouse = _warehouseService.GetByWarehouseCode(model.WarehouseCode); var location = _locationService.GetByLocationCode(model.LocationCode); var item = new Item { ProductId = product?.Id ?? null, ItemCode = model.ItemCode, Description = model.Description, CustomerId = model.CustomerId, WarehouseId = warehouse?.Id ?? null, LocationId = location?.Id ?? null, BrandId = model?.BrandId ?? brand?.Id ?? null, ReceivedBy = model.ReceivedBy, ReceivedDate = model.ReceivedDate, ExpiryDate = model.ExpiryDate, }; long retId = _itemService.AddItem(item); long itemId = 0; if (retId == 0) { itemId = _itemService.GetByItemCode(item.ItemCode, item.CustomerId).Id; } var expectedReceiptLine = _ExpectedReceiptLineRepository.GetById(expectedReceiptLineId); expectedReceiptLine.BrandId = model?.BrandId ?? brand?.Id ?? null; expectedReceiptLine.ProductId = product?.Id ?? null; expectedReceiptLine.UomId = model?.UomId ?? null; expectedReceiptLine.Quantity = model.Quantity; expectedReceiptLine.ItemCode = model.ItemCode; expectedReceiptLine.ItemDescription = model.Description; expectedReceiptLine.ItemId = retId == 0 ? itemId : retId; expectedReceiptLine.IsItemExist = true; expectedReceiptLine.StatusId = 32; _ExpectedReceiptLineRepository.Update(expectedReceiptLine); return(expectedReceiptLine.Id); }
public IHttpActionResult Get(string itemCode, long?customerId) { var item = _itemService.GetByItemCode(itemCode, customerId); if (item == null) { return(Content(HttpStatusCode.NotFound, $"Item code [{itemCode}] not found.")); } var product = _productService.GetById((int)item.ProductId); var retVal = new ItemBindingModel { ProductCode = product.ProductCode, Description = item.Description, ItemCode = item.ItemCode }; return(Ok(retVal)); }