Esempio n. 1
0
 protected void AutoMapper(Models.AutoMapperParm parm)
 {
     parm.Version = Convert.ToByte(Request.Form["Version"]);
     Models.AutoMapper mapper = new Models.AutoMapper(parm, HrUnitOfWork, User.Identity);
     mapper.Map();
 }
Esempio n. 2
0
 protected void AutoMapper(Models.AutoMapperParm parm)
 {
     Models.AutoMapper mapper = new Models.AutoMapper(parm, HrUnitOfWork, User.Identity);
     mapper.Map();
 }
Esempio n. 3
0
 private void AutoMapper(Models.AutoMapperParm parm, HrUnitOfWork unitOfWork)
 {
     Models.AutoMapper mapper = new Models.AutoMapper(parm, unitOfWork, User.Identity);
     mapper.Map();
 }
        //SaveNotification
        public ActionResult SaveNotification(NotifyConditionViewModel model, IEnumerable <FilterGridViewModel> grid1, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();
            var          msg    = "OK";

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "Notify",
                        TableName    = "NotifyConditions",
                        Columns      = Models.Utils.GetColumnViews(ModelState),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }

                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            int[] reminderEvent = { (int)Events.IsDueIn, (int)Events.IsDueTo, (int)Events.WasDueThisAmountofTimeAgo };

            var NotifyCondition = _hrUnitOfWork.Repository <NotifyCondition>().Where(a => a.Id == model.Id).FirstOrDefault();

            if (NotifyCondition == null)
            {
                NotifyCondition = new NotifyCondition();

                var parm = new Models.AutoMapperParm
                {
                    Destination = NotifyCondition,
                    Source      = model,
                    ObjectName  = "Notify",
                    Options     = moreInfo,
                    Transtype   = TransType.Insert
                };

                AutoMapper mapper = new Models.AutoMapper(parm, _hrUnitOfWork, User.Identity);
                mapper.Map();
                NotifyCondition.CompanyId   = CompanyId;
                NotifyCondition.CreatedTime = DateTime.Now;
                NotifyCondition.CreatedUser = UserName;
                NotifyCondition.ColumnName  = model.ColumnName;
                NotifyCondition.TableName   = model.TableName;
                NotifyCondition.ObjectName  = model.ObjectName;
                NotifyCondition.Version     = model.Version;
                NotifyCondition.Message     = model.EncodedMsg.Replace("&nbsp;", " ").Replace("&lt;", "<").Replace("&gt;", ">");
                NotifyCondition.EventValue  = model.EventValue;
                Events ev = (Events)Enum.ToObject(typeof(Events), model.Event);
                NotifyCondition.Event = ev;
                List <string> ListOfUsers = new List <string>();
                if (model.Users != null)
                {
                    foreach (var item in model.Users)
                    {
                        var users = db.Users.Where(a => a.Id == item).Select(a => a.UserName).FirstOrDefault();
                        ListOfUsers.Add(users);
                    }
                }
                NotifyCondition.Users = string.Join(",", ListOfUsers.ToArray());
                if (model.Message != null)
                {
                    var ListOfFields = GetFields(model.Message).Distinct().ToList();
                    if (model.HasEmpId && !ListOfFields.Contains("EmpId") && reminderEvent.Contains(model.Event))
                    {
                        ListOfFields.Add("EmpId");
                    }

                    NotifyCondition.Fields = string.Join(",", ListOfFields.ToArray());
                }


                /// Check Filter
                var columns = _hrUnitOfWork.NotificationRepository.GetColumnList(model.TableName, model.ObjectName, model.Version, model.divType, CompanyId, User.Identity.GetCulture());
                if (!String.IsNullOrEmpty(NotifyCondition.filter))
                {
                    var message = ApplyFilter(NotifyCondition.filter, columns);
                    if (!String.IsNullOrEmpty(message))
                    {
                        ModelState.AddModelError("filter", message);
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }

                if (grid1 != null)
                {
                    SaveFilterGrid(grid1, NotifyCondition);
                }

                _hrUnitOfWork.NotificationRepository.Add(NotifyCondition);
            }
            else
            {
                var parm = new Models.AutoMapperParm
                {
                    Destination = NotifyCondition,
                    Source      = model,
                    ObjectName  = "Notify",
                    Options     = moreInfo,
                    Transtype   = TransType.Update
                };

                AutoMapper mapper = new Models.AutoMapper(parm, _hrUnitOfWork, User.Identity);
                mapper.Map();
                NotifyCondition.CompanyId = User.Identity.GetDefaultCompany();
                NotifyCondition.Message   = model.EncodedMsg.Replace("&nbsp;", " ").Replace("&lt;", "<").Replace("&gt;", ">");
                Events ev = (Events)Enum.ToObject(typeof(Events), model.Event);
                NotifyCondition.Event      = ev;
                NotifyCondition.EventValue = model.EventValue;
                //NotifyCondition.CreatedTime = DateTime.Now;
                //NotifyCondition.CreatedUser = UserName;
                //NotifyCondition.ColumnName = model.ColumnName;
                //NotifyCondition.TableName = model.TableName;
                //NotifyCondition.ObjectName = model.ObjectName;
                // NotifyCondition.Version = model.Version;
                //Events ev = (Events)Enum.ToObject(typeof(Events), model.Event);
                //NotifyCondition.Event = ev;
                List <string> ListOfUsers = new List <string>();
                if (model.Users != null)
                {
                    foreach (var item in model.Users)
                    {
                        //var users = db.Users.Where(a => a.UserName == item).Select(a => a.UserName).FirstOrDefault();
                        ListOfUsers.Add(item);
                    }
                }
                NotifyCondition.Users = string.Join(",", ListOfUsers.ToArray());
                if (model.Message != null)
                {
                    var ListOfFields = GetFields(model.Message).Distinct().ToList();
                    if (model.HasEmpId && !ListOfFields.Contains("EmpId") && reminderEvent.Contains(model.Event))
                    {
                        ListOfFields.Add("EmpId");
                    }
                    NotifyCondition.Fields = string.Join(",", ListOfFields.ToArray());
                }
                //mapper.AddNotification(NotifyCondition, model.DateTimeValue, model.SourceId);
                /// Check Filter
                var columns = _hrUnitOfWork.NotificationRepository.GetColumnList(model.TableName, model.ObjectName, model.Version, model.divType, CompanyId, User.Identity.GetCulture());
                if (!String.IsNullOrEmpty(NotifyCondition.filter))
                {
                    var message = ApplyFilter(NotifyCondition.filter, columns);
                    if (!String.IsNullOrEmpty(message))
                    {
                        ModelState.AddModelError("filter", message);
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }

                if (grid1 != null)
                {
                    SaveFilterGrid(grid1, NotifyCondition);
                }
                _hrUnitOfWork.NotificationRepository.Attach(NotifyCondition);
                _hrUnitOfWork.NotificationRepository.Entry(NotifyCondition).State = EntityState.Modified;
            }
            errors = SaveChanges(Language);

            if (errors.Count() > 0)
            {
                foreach (var item in errors)
                {
                    msg = item.errors.Select(a => a.message).FirstOrDefault();
                }
                return(Json(msg));
            }

            return(Json(msg));
        }