Ejemplo n.º 1
0
        public ActionResult Delete(int?id)
        {
            var actualItem = _itemService.GetById(id.Value);
            var cm         = new HotelItemModel
            {
                Id            = actualItem.Id,
                NotNumber     = actualItem.NotNumber,
                UnitPrice     = actualItem.UnitPrice.Value,
                Barcode       = actualItem.Barcode,
                Quantity      = actualItem.Quantity,
                TotalQuantity = actualItem.TotalQuantity,
                Description   = actualItem.Description,
                Name          = actualItem.Name,
                IsActive      = true
            };

            return(View(cm));
        }
Ejemplo n.º 2
0
        public ActionResult Create(int?id, bool?saved)
        {
            HotelItemModel cm =
                new HotelItemModel {
                Id = 0, NotNumber = 100, UnitPrice = 100, Barcode = "", Quantity = 0, TotalQuantity = 0, Description = "", Name = "", IsActive = true
            };

            if (id.HasValue)
            {
                var actualItem = _itemService.GetById(id.Value);

                if (null != actualItem)
                {
                    cm = new HotelItemModel {
                        Id        = actualItem.Id, NotNumber = actualItem.NotNumber,
                        UnitPrice = actualItem.UnitPrice.Value, Barcode = actualItem.Barcode,
                        Quantity  = actualItem.Quantity, TotalQuantity = actualItem.TotalQuantity, Description = actualItem.Description, Name = actualItem.Name, IsActive = true
                    };
                }
            }

            cm.Saved = saved;
            return(View(cm));
        }
Ejemplo n.º 3
0
        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));
        }