예제 #1
0
 public ActionResult Create(CarrierViewModel carrierViewModel)
 {
     try
     {
         var carrierDTO = ConvertToCarrierDTO(carrierViewModel);
         _carrierService.Create(carrierDTO);
         TempData["AlertSuccess"] = "Operation Done!";
     }
     catch (Exception e)
     {
         this.ModelState.AddModelError("CustomError", e.Message);
         return(View());
     }
     return(RedirectToAction("Index"));
 }
예제 #2
0
        public IActionResult CreateCarrier([FromBody, SwaggerRequestBody("Carrier payload", Required = true)] CarrierDto carrierDto)
        {
            log.Info(nameof(CreateCarrier));

            try
            {
                carrierService.Create(carrierDto);

                return(Created(nameof(GetCarrierById), carrierDto));
            }
            catch (Exception e)
            {
                log.Error(e);

                return(BadRequest());
            }
        }
예제 #3
0
        public async Task <IActionResult> Create(CarrierViewModel carrier)
        {
            var userName = User.Identity.Name;
            var userId   = _userService.FindUser(userName).Id;

            if (ModelState.IsValid)
            {
                var registeredCarrier = _carrierService.GetAll(x => x.Name == Mapper.Map <CarrierDto>(carrier).Name);
                if (registeredCarrier.Count() != 0)
                {
                    ModelState.AddModelError("", "The carrier allready exists.");
                }
                else
                {
                    carrier.UserId = userId;
                    await _carrierService.Create(Mapper.Map <CarrierDto>(carrier));
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public IActionResult Create(CarrierDto carrierDto)
        {
            log.Info(nameof(Create) + ":Post");

            try
            {
                if (ModelState.IsValid)
                {
                    carrierService.Create(carrierDto);

                    return(RedirectToAction(nameof(Index)));
                }

                return(View(carrierDto));
            }
            catch (Exception e)
            {
                log.Error(e);

                return(BadRequest());
            }
        }
예제 #5
0
 public CarrierEntity Create([FromBody] CarrierEntity CarrierEntity)
 {
     return(CarrierService.Create(EmployeeEntity, CarrierEntity));
 }