Exemplo n.º 1
0
        public ActionResult Post(ProductUid vm)
        {
            ProductUid pt = vm;

            ViewBag.id = vm.GenDocTypeId;
            if (vm.ProductUIDId <= 0)
            {
                var Test = (from p in db.ProductUid where p.ProductUidName == pt.ProductUidName && p.ProductId == pt.ProductId && p.GenDocTypeId == pt.GenDocTypeId select p).ToList();
                if (Test.Count() > 0)
                {
                    ModelState.AddModelError("ProductUidName", "Already Exist");
                }
            }
            else
            {
                var Test = (from p in db.ProductUid where p.ProductUidName == pt.ProductUidName && p.ProductId == pt.ProductId && p.GenDocTypeId == pt.GenDocTypeId && p.ProductUIDId != pt.ProductUIDId select p).ToList();
                if (Test.Count() > 0)
                {
                    ModelState.AddModelError("ProductUidName", "Already Exist");
                }
            }
            if (ModelState.IsValid)
            {
                if (vm.ProductUIDId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductUidService.Create(pt);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Added),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        DocTypeId    = pt.GenDocTypeId,
                        Narration    = "Machine Name" + pt.ProductUidName,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }

                    return(RedirectToAction("Index", new { id = vm.GenDocTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    ProductUid temp = _ProductUidService.Find(pt.ProductUIDId);
                    temp.ProductUidName = pt.ProductUidName;
                    temp.IsActive       = pt.IsActive;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _ProductUidService.Update(temp);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Modified),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        DocTypeId    = pt.GenDocTypeId,
                        Narration    = "Machine Name" + pt.ProductUidName,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }
                    return(RedirectToAction("Index", new { id = vm.GenDocTypeId }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
Exemplo n.º 2
0
        public ActionResult Post(ProductUid vm)
        {
            ProductUid pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductUIDId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductUidService.Create(pt);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Added),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        Narration    = "A new ProductUid is created with the Id " + pt.ProductUIDId,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    ProductUid temp = _ProductUidService.Find(pt.ProductUIDId);
                    temp.ProductUidName = pt.ProductUidName;
                    temp.IsActive       = pt.IsActive;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _ProductUidService.Update(temp);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Modified),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        Narration    = "Delivery Terms is modified with the name" + pt.ProductUidName,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }