Example #1
0
        public HttpResponseMessage Create(HttpRequestMessage request, SizeViewModel SizeCategoryVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newSize = new Size();
                    newSize.UpdateSize(SizeCategoryVm);
                    newSize.CreatedDate = DateTime.Now;
                    newSize.CreatedBy = User.Identity.Name;
                    _SizeService.Add(newSize);
                    _SizeService.SaveChanges();

                    var responseData = Mapper.Map <Size, SizeViewModel>(newSize);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Example #2
0
 public IActionResult Create([FromBody] SizeViewModel sizeViewModel)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     _sizeService.Add(sizeViewModel);
     _sizeService.Save();
     return(new NoContentResult());
 }
Example #3
0
        public ActionResult Create(SizeCreateViewModel sizeCreateViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(sizeCreateViewModel));
            }

            _sizeService.Add(sizeCreateViewModel);

            return(RedirectToAction("Index"));
        }
Example #4
0
 public JavaScriptResult Create(SizeViewModel sizevm)
 {
     try
     {
         _sizeService.Add(Mapper.Map <Size>(sizevm));
         return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/APanel/Size"}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','failure')"));
     }
 }
Example #5
0
 public async Task <IActionResult> SaveEntity(SizeViewModel sizeVm)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     else
     {
         if (sizeVm.Id == 0)
         {
             await _sizeService.Add(sizeVm);
         }
         else
         {
             await _sizeService.Update(sizeVm);
         }
         _sizeService.SaveChanges();
         return(new OkObjectResult(sizeVm));
     }
 }
Example #6
0
 public HttpResponseMessage Create(HttpRequestMessage request, SizeViewModel sizeVm)
 {
     if (ModelState.IsValid)
     {
         var newSize = new Size();
         newSize.UpdateSize(sizeVm);
         try
         {
             _sizeService.Add(newSize);
             _sizeService.Save();
             return(request.CreateResponse(HttpStatusCode.OK, sizeVm));
         }
         catch (NameDuplicatedException dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
Example #7
0
        public HttpResponseMessage Create(HttpRequestMessage request, SizeViewModel model)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                var identity = (ClaimsIdentity)User.Identity;

                IEnumerable<Claim> claims = identity.Claims;

                var newSizeModel = new Size();

                newSizeModel.UpdateSize(model);

                _sizeService.Add(newSizeModel);

                _sizeService.Save();

                Log log = new Log()
                {
                    AppUserId = claims.FirstOrDefault().Value,
                    Content = Notification.CREATE_SIZE,
                    Created = DateTime.Now
                };

                _logService.Create(log);

                _logService.Save();

                var responseData = Mapper.Map<Size, SizeViewModel>(newSizeModel);

                response = request.CreateResponse(HttpStatusCode.OK, responseData);

                return response;
            });
        }
Example #8
0
        public ActionResult Post(Size ptt)
        {
            Size pt = ptt;

            if (ptt.Area == 0)
            {
                PrepareViewBag();
                string message = "Area field is required";
                ModelState.AddModelError("", message);
                ViewBag.Mode = "Add";
                return(View("Create", ptt));
            }

            if (ptt.Perimeter == 0)
            {
                PrepareViewBag();
                string message = "Perimeter field is required";
                ModelState.AddModelError("", message);
                ViewBag.Mode = "Add";
                return(View("Create", ptt));
            }

            if (ModelState.IsValid)
            {
                if (ptt.SizeId <= 0)
                {
                    ptt.CreatedDate  = DateTime.Now;
                    ptt.ModifiedDate = DateTime.Now;
                    ptt.CreatedBy    = User.Identity.Name;
                    ptt.ModifiedBy   = User.Identity.Name;
                    ptt.ObjectState  = Model.ObjectState.Added;
                    var createdSize = _SizeService.Add(ptt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        PrepareViewBag();
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.Mode = "Add";
                        return(View("Create", ptt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Size).DocumentTypeId,
                        DocId        = pt.SizeId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }

                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    Size temp = _SizeService.Find(pt.SizeId);

                    Size ExRec = Mapper.Map <Size>(temp);

                    temp.SizeName       = pt.SizeName;
                    temp.ProductShapeId = pt.ProductShapeId;
                    temp.UnitId         = pt.UnitId;
                    temp.DocTypeId      = pt.DocTypeId;
                    temp.Length         = pt.Length;
                    temp.LengthFraction = pt.LengthFraction;
                    temp.Width          = pt.Width;
                    temp.WidthFraction  = pt.WidthFraction;
                    temp.Height         = pt.Height;
                    temp.HeightFraction = pt.HeightFraction;
                    temp.Area           = pt.Area;
                    temp.Perimeter      = pt.Perimeter;
                    temp.IsActive       = pt.IsActive;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _SizeService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.Mode = "Edit";
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Size).DocumentTypeId,
                        DocId           = temp.SizeId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            ViewBag.Mode = "Add";
            return(View(ptt));
        }
Example #9
0
 public ActionResult Create(Size size)
 {
     _sizeService.Add(size);
     return(RedirectToAction("Index"));
 }