Пример #1
0
        public async Task <IActionResult> Create([Bind("Name,ImageUrl,Description ,File")] OutletCreateViewModel outletViewModel)
        {
            try
            {
                if (outletViewModel.File == null || outletViewModel.File.Length <= 0)
                {
                    ModelState.AddModelError("", "Outlet logo requried");
                }
                if (ModelState.IsValid)
                {
                    outletViewModel.ImageUrl = await _fileServices.SaveFile(outletViewModel.File);

                    var outlet = _mapper.Map <Outlet>(outletViewModel);
                    await _outletService.AddOutlet(outlet);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message.ToString());
                return(View(outletViewModel));
            }

            return(View(outletViewModel));
        }
Пример #2
0
        public IActionResult AddOutlet(Outlet outlet)
        {
            Outlet addedOutlet = _outletData.AddOutlet(outlet);

            if (addedOutlet != null)
            {
                return(Created(HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + outlet.Id, outlet));
            }

            return(NotFound("Cannot add outlets with redundant names having the same dates of opening. "));
        }
Пример #3
0
        public bool Post(OutletDto outletmodel)
        {
            var outletin = _mapper.Map <Outlet1>(outletmodel);

            return(_outletservice.AddOutlet((outletin)));
        }