public long AddInventory(InventoryAddModel model)
        {
            try
            {
                var sqlQuery = GetAddInventoryQuery(model);

                var result = _db.ExecuteScalar <long>(sqlQuery, new
                {
                    @brandName     = model.BrandName,
                    @name          = model.Name,
                    @inventoryCode = model.InventoryCode,
                    @imagePath     = model.ImagePath,
                    @createdBy     = SessionRegistry.GetUserData().Id,
                    @createdDate   = DateTime.Now,
                    @modifiedBy    = SessionRegistry.GetUserData().Id,
                    @modifiedDate  = DateTime.Now,
                    @volumeType    = model.VolumeType,
                    @volume        = model.Volume,
                    @specification = model.Specification.Replace("'", "''"),
                    @inPrice       = model.InPrice,
                    @outPrice      = model.OutPriceIncVat,
                    @rea           = model.REA,
                    @supplier      = model.Supplier
                });
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        private static string GetEditInventoryQuery(InventoryAddModel model)
        {
            var sqlQuery = new StringBuilder();

            sqlQuery.Append(string.Format(@"UPDATE Inventory SET BrandName='{0}',Name='{1}',InventoryCode='{2}',ModifiedBy={3},ModifiedDate='{4}',ImagePath='{5}',VolumeType='{6}',Supplier='{7}',InPrice='{8}',OutPriceIncVat='{9}',REA={10},Volume='{11}',Specification='{12}' WHERE Id={13} ", model.BrandName, model.Name, model.InventoryCode, SessionRegistry.GetUserData().Id, DateTime.Now, model.ImagePath, model.VolumeType, model.Supplier, model.InPrice, model.OutPriceIncVat, model.REA, model.Volume, model.Specification, model.Id));
            return(sqlQuery.ToString());
        }
        public ActionResult AddInventory(InventoryAddModel model, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                if (!_inventoryService.IsInventoryCodeExists(model.InventoryCode))
                {
                    model.ImagePath = (string.IsNullOrEmpty(Convert.ToString(imagePath))) ? "" : string.Format("~/InventoryUpload/{0}-{1}", Guid.NewGuid(), imagePath.FileName);

                    var result = _inventoryService.AddInventory(model);
                    if (result > 0)
                    {
                        if (!string.IsNullOrWhiteSpace(model.ImagePath))
                        {
                            imagePath.SaveAs(Server.MapPath(model.ImagePath));
                        }

                        return(RedirectToAction("Index", "InventoryWeb").WithSuccess("Inventarielista är tillagd."));
                    }
                    else
                    {
                        return(View().WithError("Ett fel har uppstått vid tillagd inventarielista."));
                    }
                }
                else
                {
                    return(View().WithError("Inventariekod är redan tillgänglig för en existerande produkt."));
                }
            }
            return(View(model));
        }
        public ActionResult EditInventory(InventoryAddModel model, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                model.ImagePath = (string.IsNullOrEmpty(Convert.ToString(imagePath))) ? model.FileUrl : string.Format("~/InventoryUpload/{0}-{1}", Guid.NewGuid(), imagePath.FileName);
                var result = _inventoryService.EditInventory(model);
                if (result > 0)
                {
                    if (model.ImagePath != model.FileUrl)
                    {
                        imagePath.SaveAs(Server.MapPath(model.ImagePath));
                        if (System.IO.File.Exists(model.FileUrl))
                        {
                            System.IO.File.Delete(model.FileUrl);
                        }
                    }


                    return(RedirectToAction("Index", "InventoryWeb").WithSuccess("Inventarielistan har blivit uppdaterad."));
                }
                else
                {
                    return(View().WithError("Error en els detalls de l'inventari d'actualització."));
                }
            }
            else
            {
                model.ImagePath = model.FileUrl;
            }
            return(View(model));
        }
        private static string GetAddInventoryQuery(InventoryAddModel model)
        {
            var sqlQuery = new StringBuilder();

            sqlQuery.Append(@"INSERT INTO Inventory(BrandName,Name,InventoryCode,ImagePath,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate,VolumeType,Supplier,InPrice,OutPriceIncVat,Volume,Specification,REA) 
                              VALUES(@brandName,@name,@inventoryCode,@imagePath,@createdBy,@createdDate,@modifiedBy,@modifiedDate,@volumeType,@supplier,@inPrice,@outPrice,@volume,@specification,@rea); SELECT SCOPE_IDENTITY(); ");
            return(sqlQuery.ToString());
        }
 public long EditInventory(InventoryAddModel model)
 {
     try
     {
         model.Name          = model.Name.Replace("\r\n", string.Empty).Replace("'", "''").Replace(",", "");
         model.Specification = model.Specification.Replace("\r\n", string.Empty).Replace("'", "''").Replace(",", "");
         var sqlQuery = GetEditInventoryQuery(model);
         var result   = _db.ExecuteScalar <long>(sqlQuery);
         return(1);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message.ToString());
     }
 }
Beispiel #7
0
 public long EditInventory(InventoryAddModel model)
 {
     return(_inventoryRepository.EditInventory(model));
 }