Example #1
0
 public void Update(DocumentTypeTimeExtension pt, string UserName)
 {
     pt.ModifiedBy   = UserName;
     pt.ModifiedDate = DateTime.Now;
     pt.ObjectState  = ObjectState.Modified;
     db.DocumentTypeTimeExtension.Add(pt);
 }
Example #2
0
        public void Delete(int id)
        {
            DocumentTypeTimeExtension pd = db.DocumentTypeTimeExtension.Find(id);

            pd.ObjectState = Model.ObjectState.Deleted;
            db.DocumentTypeTimeExtension.Remove(pd);
        }
Example #3
0
        public DocumentTypeTimeExtension Create(DocumentTypeTimeExtension pt, string UserName)
        {
            pt.CreatedBy    = UserName;
            pt.CreatedDate  = DateTime.Now;
            pt.ModifiedBy   = UserName;
            pt.ModifiedDate = DateTime.Now;

            pt.ObjectState = ObjectState.Added;
            db.DocumentTypeTimeExtension.Add(pt);

            return(pt);
        }
        // GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)
        {
            DocumentTypeTimeExtension pt = _DocumentTypeTimeExtensionService.Find(id);

            DocumentTypeTimeExtensionViewModel Temp = Mapper.Map <DocumentTypeTimeExtension, DocumentTypeTimeExtensionViewModel>(pt);

            PrepareViewBag();
            if (pt == null)
            {
                return(HttpNotFound());
            }
            return(View("Create", Temp));
        }
        // GET: /ProductMaster/Delete/5

        public ActionResult Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DocumentTypeTimeExtension DocumentTypeTimeExtension = _DocumentTypeTimeExtensionService.Find(id);

            if (DocumentTypeTimeExtension == null)
            {
                return(HttpNotFound());
            }

            ReasonViewModel vm = new ReasonViewModel()
            {
                id = id,
            };

            return(PartialView("_Reason", vm));
        }
        public async Task NotifyUser(int id)//TaskId
        {
            DocumentTypeTimeExtension Temp = db.DocumentTypeTimeExtension.Find(id);

            db.Entry <DocumentTypeTimeExtension>(Temp).Reference(m => m.DocType).Load();

            Notification NN = new Notification();

            NN.NotificationSubjectId = (int)NotificationSubjectConstants.PermissionAssigned;
            NN.CreatedBy             = User.Identity.Name;
            NN.CreatedDate           = DateTime.Now;
            NN.ExpiryDate            = DateTime.Now.AddDays(1);
            NN.IsActive         = true;
            NN.ModifiedBy       = User.Identity.Name;
            NN.ModifiedDate     = DateTime.Now;
            NN.NotificationText = "Permission assigned for " + Temp.DocType.DocumentTypeName + " dated " + Temp.DocDate.ToString("dd/MMM/yyyy");


            TaskNotification nc = new TaskNotification();
            await nc.CreateTaskNotificationAsync(NN, Temp.UserName);
        }
        public bool ValidateDocument(DocumentUniqueId Args, string Type, string UserName, out string Msg, out bool Continue)
        {
            List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"];

            Continue = UserRoles.Contains("Admin");
            Msg      = "";

            DateTime Today          = DateTime.Now.Date;
            Decimal  MaxAllowedDays = 0;
            Decimal  MaxBackDays    = 0;

            DocumentTypeTimeExtension TimeExtension = (from p in _documentTypeTimeExtension.Instance
                                                       where p.DocTypeId == Args.DocTypeId &&
                                                       p.SiteId == Args.SiteId && p.DivisionId == Args.DivisionId &&
                                                       p.Type == Type && p.ExpiryDate >= Today && p.UserName == UserName && Args.DocDate.Date == p.DocDate
                                                       select p).FirstOrDefault();


            DocumentTypeTimePlan TimePlan = (from p in _documentTypeTimePlan.Instance
                                             where p.DocTypeId == Args.DocTypeId &&
                                             p.SiteId == Args.SiteId && p.DivisionId == Args.DivisionId &&
                                             p.Type == Type
                                             select p).FirstOrDefault();

            if (TimePlan != null)
            {
                MaxAllowedDays = TimePlan.Days;
            }


            DocumentTypeTimePlan TimePlanBackDays = (from p in _documentTypeTimePlan.Instance
                                                     where p.DocTypeId == Args.DocTypeId &&
                                                     p.SiteId == Args.SiteId && p.DivisionId == Args.DivisionId &&
                                                     p.Type == DocumentTimePlanTypeConstants.Create
                                                     select p).FirstOrDefault();

            DocumentTypeTimeExtension BackDaysTimeExtension = (from p in _documentTypeTimeExtension.Instance
                                                               where p.DocTypeId == Args.DocTypeId &&
                                                               p.SiteId == Args.SiteId && p.DivisionId == Args.DivisionId &&
                                                               p.Type == DocumentTimePlanTypeConstants.Create && p.UserName == UserName && Args.DocDate.Date == p.DocDate
                                                               select p).FirstOrDefault();

            if (TimePlanBackDays != null)
            {
                MaxBackDays = TimePlanBackDays.Days;
            }



            switch (Type)
            {
            case DocumentTimePlanTypeConstants.Create:
            {
                if (TimePlan != null && (((DateTime.Now.Date - Args.DocDate.Date.Date).Days) > MaxAllowedDays) && TimeExtension == null)
                {
                    Msg = MaxAllowedDays != 0 ? "You cannot Create record older than " + string.Format("{0:0}", MaxAllowedDays) + " days" : "You cannot Create record older than today. <br />";
                }
                else
                {
                    Msg = "";
                }
                break;
            }

            case DocumentTimePlanTypeConstants.Modify:
            {
                if (TimePlan != null && (((DateTime.Now.Date - (Args.CreatedDate == null ? DateTime.Now.Date : Args.CreatedDate.Date)).Days) > MaxAllowedDays) && TimeExtension == null && Args.Status == (int)StatusConstants.Submitted)
                {
                    Msg = MaxAllowedDays > 0 ? "You cannot Modify record older than " + string.Format("{0:0}", MaxAllowedDays) + " days" : "You cannot Modify record older than today. <br />";
                }
                else
                {
                    if ((TimePlanBackDays != null && ((((Args.CreatedDate == null ? DateTime.Now.Date : Args.CreatedDate.Date) - Args.DocDate.Date).Days) > MaxBackDays)) && Args.Status == (int)StatusConstants.Submitted && BackDaysTimeExtension == null)
                    {
                        Msg = MaxAllowedDays > 0 ? "You cannot Create record older than " + string.Format("{0:0}", MaxBackDays) + " days" : "You cannot Create record older than today. <br />";
                    }
                    else
                    {
                        Msg = "";
                    }
                }


                if ((Args.Status == (int)StatusConstants.Drafted || Args.Status == (int)StatusConstants.Modified) && !string.IsNullOrEmpty(Args.ModifiedBy) && Args.ModifiedBy != UserName)
                {
                    Msg += "Record must be submitted before modification. <br />";
                }

                if (Args.GatePassHeaderId.HasValue && Args.GatePassHeaderId.Value > 0)
                {
                    Msg += "Cannot modify record whose gatepass is generated. <br />";
                }

                if (!string.IsNullOrEmpty(Args.LockReason))
                {
                    Msg += "Record Locked: " + Args.LockReason + ". <br />";
                }

                break;
            }

            case DocumentTimePlanTypeConstants.Submit:
            {
                if (TimePlan != null && (((DateTime.Now.Date - (Args.CreatedDate == null ? DateTime.Now.Date : (Args.Status == (int)StatusConstants.Modified ? Args.ModifiedDate.Date : Args.CreatedDate.Date))).Days) > (Args.Status == (int)StatusConstants.Modified ? 1 : MaxAllowedDays)) && TimeExtension == null)
                {
                    Msg = Args.Status == (int)StatusConstants.Modified ? "You cannot Submit modified record older than one day. <br />" : (MaxAllowedDays != 0 ? "You cannot Submit record older than " + string.Format("{0:0}", MaxAllowedDays) + " days." : "You cannot Submit record older than today. <br />");
                }
                else
                {
                    Msg = "";
                }
                break;
            }

            case DocumentTimePlanTypeConstants.Delete:
            {
                if (TimePlan != null && (((DateTime.Now.Date - (Args.CreatedDate == null ? DateTime.Now.Date : Args.CreatedDate.Date)).Days) > MaxAllowedDays) && TimeExtension == null)
                {
                    Msg = MaxAllowedDays > 0 ? "You cannot Delete record older than " + string.Format("{0:0}", MaxAllowedDays) + " days." : "You cannot Delete record older than today. <br />";
                }
                else
                {
                    Msg = "";
                }

                if (!string.IsNullOrEmpty(Args.LockReason))
                {
                    Msg += "Record Locked: " + Args.LockReason + ". <br />";
                }

                break;
            }

            case DocumentTimePlanTypeConstants.GatePassCreate:
            {
                if (TimePlan != null && (((DateTime.Now.Date - (Args.ModifiedDate.Date)).Days) > MaxAllowedDays) && TimeExtension == null)
                {
                    Msg = Args.DocNo + "<br />" + (MaxAllowedDays != 0 ? "You cannot Generate gatepass older than " + string.Format("{0:0}", MaxAllowedDays) + " days." : "You cannot generate gatepass older than today. <br />");
                }
                else
                {
                    Msg = "";
                }
                break;
            }

            case DocumentTimePlanTypeConstants.GatePassCancel:
            {
                var GatePass = _unitOfWork.Repository <GatePassHeader>().Find(Args.GatePassHeaderId);

                if (GatePass.Status != (int)StatusConstants.Drafted)
                {
                    Msg = "Cannot cancel a submitted gatepass.";
                }
                else if (TimePlan != null && (((DateTime.Now.Date - GatePass.CreatedDate).Days) > (MaxAllowedDays)) && TimeExtension == null)
                {
                    Msg = Args.DocNo + "<br />" + (MaxAllowedDays != 0 ? "You cannot Cancel gatepass older than " + string.Format("{0:0}", MaxAllowedDays) + " days." : "You cannot Cancel gatepass older than today. <br />");
                }
                else
                {
                    Msg = "";
                }
                break;
            }
            }

            return(string.IsNullOrEmpty(Msg));
        }
        public ActionResult Post(DocumentTypeTimeExtensionViewModel vm)
        {
            DocumentTypeTimeExtension pt = Mapper.Map <DocumentTypeTimeExtensionViewModel, DocumentTypeTimeExtension>(vm);

            if (ModelState.IsValid)
            {
                var DocType = db.DocumentType.Where(m => m.DocumentTypeName == MasterDocTypeConstants.DocumentTypeTimeExtension).FirstOrDefault();

                if (vm.DocumentTypeTimeExtensionId <= 0)
                {
                    _DocumentTypeTimeExtensionService.Create(pt, User.Identity.Name);

                    try
                    {
                        db.SaveChanges();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = DocType.DocumentTypeId,
                        DocId        = pt.DocumentTypeTimeExtensionId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    NotifyUser(pt.DocumentTypeTimeExtensionId);

                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    DocumentTypeTimeExtension temp = _DocumentTypeTimeExtensionService.Find(pt.DocumentTypeTimeExtensionId);

                    DocumentTypeTimeExtension ExRec = Mapper.Map <DocumentTypeTimeExtension>(pt);

                    temp.DocTypeId   = pt.DocTypeId;
                    temp.Type        = pt.Type;
                    temp.ExpiryDate  = pt.ExpiryDate;
                    temp.UserName    = pt.UserName;
                    temp.Reason      = pt.Reason;
                    temp.NoOfRecords = pt.NoOfRecords;
                    temp.DocDate     = pt.DocDate;

                    _DocumentTypeTimeExtensionService.Update(temp, User.Identity.Name);

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

                    try
                    {
                        db.SaveChanges();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = DocType.DocumentTypeId,
                        DocId           = temp.DocumentTypeTimeExtensionId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
Example #9
0
 public void Delete(DocumentTypeTimeExtension pt)
 {
     pt.ObjectState = Model.ObjectState.Deleted;
     db.DocumentTypeTimeExtension.Remove(pt);
 }