Exemple #1
0
        public ActionResult Create([Bind(Include = "Name")] Vendor item)
        {
            if (_service == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            try
            {
                item.CreatedOn = DateTime.UtcNow;
                item.UpdatedOn = item.UpdatedOn ?? DateTime.UtcNow;
                item.OrgId     = null; //FK will be a prob until we get real data

                if (ModelState.IsValid)
                {
                    var added = _service.Add(item);

                    if (added != null)
                    {
                        _context.SaveChanges();
                    }

                    return(RedirectToAction("VendorIndex"));
                }
            }
            catch (DataException dex)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                Audit.Log.Error("Error on creation", dex);
                ModelState.AddModelError("",
                                         "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(item));
        }
Exemple #2
0
        // POST api/<controller>
        public IHttpActionResult Post(object obj)
        {
            try
            {
                var retId = _vendorService.Add(obj);

                bool IsDuplicate = retId == 0;
                if (IsDuplicate == true)
                {
                    Log.Info($"{typeof(VendorController).FullName}||{UserEnvironment}||Add record not successful, Vendor Name is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Vendor Name is Duplicate"));
                }

                Log.Info($"{typeof(VendorController).FullName}||{UserEnvironment}||Add record successful.");

                var response = Request.CreateResponse(HttpStatusCode.Created);
                var test     = JsonConvert.SerializeObject(new
                {
                    id      = retId,
                    message = "Vendor added"
                });
                response.Content = new StringContent(test, Encoding.UTF8, "appliation/json");
                return(ResponseMessage(response));
            }
            catch (Exception e)
            {
                Log.Error(typeof(VendorController).FullName, e);

                return(Content(HttpStatusCode.NotAcceptable, e.Message));
            }
        }
        public async Task <ActionResult <VendorDTO> > Add(VendorDTO vendorDTO)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var vendor = _mapper.Map <Vendor>(vendorDTO);
            await _vendorService.Add(vendor);

            return(CustomResponse(vendorDTO));
        }
Exemple #4
0
        public async Task <IActionResult> Post([FromBody] Vendor vendor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _vendorService.Add(vendor);
            await _unitOfWork.SaveChangesAsync();

            return(Ok(vendor));
        }
Exemple #5
0
        public async Task <IActionResult> Create(VendorViewModel vendorView)
        {
            if (!ModelState.IsValid)
            {
                return(View(vendorView));
            }

            var vendor = _mapper.Map <Vendor>(vendorView);

            await _vendorService.Add(vendor);

            if (!OperationIsValid())
            {
                return(View(vendorView));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public void Can_Add_Vendor()
        {
            //Arrange
            var Id   = 1;
            var pers = new Entity.Model.Vendor {
                Name = "ACME2"
            };

            _mockRepository.Setup(m => m.Add(pers)).Returns((Entity.Model.Vendor e) =>
            {
                e.Id = Id;
                return(e);
            });

            //Act
            var added = _service.Add(pers);

            Assert.IsNotNull(added);

            //Assert
            Assert.AreEqual(Id, pers.Id);
            _mockUnitWork.Verify(m => m.Commit(), Times.Once);
        }
        public ActionResult <ItemResponse <int> > Create(VendorAddRequest model)
        {
            ObjectResult result = null;
            int          userId = _authService.GetCurrentUserId();

            try
            {
                int id = _service.Add(model, userId);
                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };

                result = Created201(response);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                ErrorResponse response = new ErrorResponse(ex.Message);

                result = StatusCode(500, response);
            }
            return(result);
        }