Ejemplo n.º 1
0
        public SalePersonViewModel Create()
        {
            SalePersonViewModel model = new SalePersonViewModel();

            model.ShopList = new SelectList(_shopService.GetShops(), "Id", "ShopName");
            return(model);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, SalePersonViewModel model)
        {
            try
            {
                bool result = _salesPersonService.UpdateSalePerson(model);

                if (result)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!");
                return(View());
            }
        }
Ejemplo n.º 3
0
        public bool AddSalePerson(SalePersonViewModel model)
        {
            try
            {
                SalePerson salesPerson = new SalePerson
                {
                    Surname   = model.Surname,
                    OtherName = model.Othername,
                    Gender    = model.Gender.ToString(),
                    ShopId    = model.ShopId
                };

                _context.SalePerson.Add(salesPerson);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public bool UpdateSalePerson(SalePersonViewModel model)
        {
            try
            {
                SalePerson salesPerson = _context.SalePerson.Where(x => x.SalePersonId == model.Id).FirstOrDefault();

                salesPerson.Surname   = model.Surname;
                salesPerson.OtherName = model.Othername;
                salesPerson.Gender    = model.Gender.ToString();
                salesPerson.ShopId    = model.ShopId;

                _context.SalePerson.Update(salesPerson);
                _context.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        public SalePersonViewModel GetSalePersonDetails(int id)
        {
            try
            {
                SalePerson salesPerson = _context.SalePerson.Where(x => x.SalePersonId == id).Include(x => x.Shop).FirstOrDefault();

                SalePersonViewModel viewModel = new SalePersonViewModel
                {
                    Id        = salesPerson.SalePersonId,
                    Surname   = salesPerson.Surname,
                    Othername = salesPerson.OtherName,
                    Gender    = Convert.ToChar(salesPerson.Gender),
                    ShopId    = salesPerson.ShopId,
                    ShopName  = salesPerson.Shop.ShopName,
                    ShopList  = new SelectList(_shopService.GetShops(), "Id", "ShopName", salesPerson.ShopId)
                };

                return(viewModel);
            }
            catch (Exception)
            {
                throw;
            }
        }