Esempio n. 1
0
 public StockItemHotel Create(StockItemHotel StockItemHotel)
 {
     _unitOfWork.StockItemHotelRepository.Insert(StockItemHotel);
     _unitOfWork.Save();
     return(StockItemHotel);
 }
Esempio n. 2
0
 public StockItemHotel Update(StockItemHotel StockItemHotel)
 {
     _unitOfWork.StockItemHotelRepository.Update(StockItemHotel);
     _unitOfWork.Save();
     return(StockItemHotel);
 }
Esempio n. 3
0
 public void Delete(StockItemHotel StockItemHotel)
 {
     _unitOfWork.StockItemHotelRepository.Delete(StockItemHotel);
     _unitOfWork.Save();
 }
        public ActionResult Create(HotelItemModel cm)
        {
            int id = 0;

            var alltems = _itemService.GetAll().ToList();

            StockItemHotel existingBarcode = null;

            if (!string.IsNullOrEmpty(cm.Barcode))
            {
                existingBarcode = alltems.FirstOrDefault(x => x.Barcode == cm.Barcode);

                if (cm.Id == 0)
                {
                    if (existingBarcode != null)
                    {
                        ModelState.AddModelError("BarCode", "Please use a different barcode. This barcode exists for a different item");
                    }
                }
                else
                {
                    if (existingBarcode != null && existingBarcode.Id != cm.Id)
                    {
                        ModelState.AddModelError("BarCode", "Please use a different barcode. This barcode exists for a different item");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var existingItem = alltems.FirstOrDefault(x => x.Name.Equals(cm.Name, StringComparison.InvariantCultureIgnoreCase));

                if (existingItem != null && existingItem.Id > 0)
                {
                    cm.IsActive = true;

                    cm.TotalQuantity = cm.Quantity;

                    if (string.IsNullOrEmpty(cm.Barcode))
                    {
                        cm.Barcode = "";
                    }

                    existingItem.IsActive    = true;
                    existingItem.Barcode     = cm.Barcode;
                    existingItem.Name        = cm.Name;
                    existingItem.Description = cm.Description;
                    existingItem.UnitPrice   = cm.UnitPrice;
                    existingItem.NotNumber   = cm.NotNumber;

                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Products"), fileName);
                        file.SaveAs(path);
                        existingItem.PicturePath = fileName;
                    }

                    _itemService.Update(existingItem);

                    id = existingItem.Id;
                }
                else
                {
                    cm.IsActive = true;

                    cm.TotalQuantity = cm.Quantity;

                    if (string.IsNullOrEmpty(cm.PicturePath))
                    {
                        cm.PicturePath = "default.png";
                    }

                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Products"), fileName);
                        file.SaveAs(path);
                        cm.PicturePath = fileName;
                    }

                    var newItem = _itemService.Create(new StockItemHotel
                    {
                        Barcode     = cm.Barcode,
                        Description = cm.Description, IsActive = true, Name = cm.Name, NotNumber = cm.NotNumber, PicturePath = cm.PicturePath,
                        Quantity    = cm.Quantity, TotalQuantity = cm.Quantity, UnitPrice = cm.UnitPrice
                    });

                    id = newItem.Id;
                }

                bool saved = true;

                return(RedirectToAction("Create", new { id, saved }));
            }
            return(View(cm));
        }