示例#1
0
        public ActionResult Login(LoginUserModel model)
        {
            if (string.IsNullOrEmpty(model.UserName) || string.IsNullOrWhiteSpace(model.UserName))
            {
                ModelState.AddModelError(string.Empty, "用户名不能为空.");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.Password) || string.IsNullOrWhiteSpace(model.Password))
            {
                ModelState.AddModelError(string.Empty, "密码不能为空.");
                return(View(model));
            }

            var userModel = UserService.Login(model);

            if (userModel == null)
            {
                ModelState.AddModelError(string.Empty, "无效的用户名或密码.");
                return(View(model));
            }
            else if (!userModel.IsAssetManager && !userModel.IsAdminStaff) //判断登录且用户角色为行政专员或资产管理员
            {
                ModelState.AddModelError(string.Empty, "用户无登录权限.");
                return(View(model));
            }
            else
            {
                CommonInstance.GetInstance().LoginUser = userModel;
                FormsAuthentication.SetAuthCookie(model.UserName, false);
                //HttpCookie cookie = new HttpCookie(COOKIE_NAME, model.UserName);
                //cookie.Expires = DateTime.Now.AddDays(30);
                //Response.AppendCookie(cookie);
                return(RedirectToAction("Index", "User"));
            }
        }
        public ActionResult Edit(ProjectModel model)
        {
            string action = Request["Submit"];

            if (action == "cancel")
            {
                return(RedirectToAction("Index"));
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("Name", "请输入项目组名称");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Id > 0)
                    {
                        ProjectModel projectModel = new ProjectModel()
                        {
                            Name           = model.Name,
                            ProjectManager = model.ProjectManager,
                            ProjectBegin   = model.ProjectBegin,
                            ProjectEnd     = model.ProjectEnd,
                        };
                        this.ProjectService.UpdateProject(model.Id, projectModel);
                    }
                    else
                    {
                        model.Status         = 1;
                        model.CreateUserName = CommonInstance.GetInstance().LoginUser.EnglishName;
                        model.CreatedTime    = DateTime.Now;
                        this.ProjectService.AddProject(model);
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }
            var userList = new List <SelectListItem>();
            var allUsers = UserService.GetAllUsers();

            //userList.Add(new SelectListItem() { Value = "0", Text = "--Please select management--" });
            foreach (UserModel p in allUsers)
            {
                userList.Add(new SelectListItem()
                {
                    Value = (p.Id).ToString(), Text = p.EnglishName
                });
            }
            ViewData["ProjectManagerList"] = new SelectList(userList, "Value", "Text", (int)model.ProjectManager);
            return(View(model));
        }
示例#3
0
        public ActionResult Edit(MeetingRoomModel model)
        {
            string action = Request["Submit"];

            if (action == "cancel")
            {
                return(RedirectToAction("Index"));
            }

            if (string.IsNullOrEmpty(model.MeetingRoomName))
            {
                ModelState.AddModelError("MeetingRoomName", "请输入会议室名.");
            }

            if (string.IsNullOrEmpty(model.Equipment))
            {
                ModelState.AddModelError("Equipment", "请输入设备.");
            }

            if ((model.Capacity) == 0)
            {
                ModelState.AddModelError("Capacity", "请输入可容纳人数.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Id > 0)
                    {
                        this.MeetingService.UpdateMeetingRoom(model);
                    }
                    else
                    {
                        model.CreateDate     = DateTime.Now;
                        model.CreateUserName = CommonInstance.GetInstance().LoginUser.EnglishName;
                        this.MeetingService.AddMeetingRoom(model);
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }

            return(View(model));
        }
示例#4
0
        public ActionResult Edit(RoleModel model)
        {
            string action = Request["Submit"];

            if (action == "cancel")
            {
                return(RedirectToAction("Index"));
            }
            if (string.IsNullOrEmpty(model.Abbreviation))
            {
                ModelState.AddModelError("Abbreviation", "英文简称不能为空");
            }
            if (string.IsNullOrEmpty(model.RoleName))
            {
                ModelState.AddModelError("RoleName", "角色名不能为空");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Id > 0)
                    {
                        RoleModel updateUserModel = new RoleModel()
                        {
                            RoleName = model.RoleName,
                            Status   = model.Status
                        };
                        this.RoleService.UpdateRole(model.Id, updateUserModel);
                    }
                    else
                    {
                        model.CreatedTime = DateTime.Now;
                        model.CreateUser  = CommonInstance.GetInstance().LoginUser.EnglishName;
                        model.IsInitRole  = 0;
                        this.RoleService.AddRole(model);
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }

            return(View(model));
        }
        public ActionResult Edit(NotificationModel model)
        {
            string action = Request["Submit"];

            if (action == "cancel")
            {
                return(RedirectToAction("Index"));
            }

            if (string.IsNullOrEmpty(model.Title))
            {
                ModelState.AddModelError("Title", "请输入标题.");
            }

            if (string.IsNullOrEmpty(model.MessageContent))
            {
                ModelState.AddModelError("MessageContent", "请输入通知内容.");
            }
            //model.MessageType = NotificationType.PushMessage;
            model.MessageType   = NotificationType.Email;
            model.CreatedUserId = CommonInstance.GetInstance().LoginUser.Id;
            model.Scope         = NotificationScope.Public;
            model.Title         = model.Title;
            if (action == "test")
            {
                //model.Target = "*****@*****.**";
                //model.CreatedUserId = CommonInstance.GetInstance().LoginUser.Id;
                //model.MessageType = NotificationType.PushMessage;
                //model.BusinessType = BusinessType.Approving;
                //model.Title = "Missionsky OA Test";
                //model.MessageContent = "Kevin Test- to Kevin";
                //model.MessagePrams = "test";
                //model.Scope = NotificationScope.User;
                //model.TargetUserIds = new List<int> { CommonInstance.GetInstance().LoginUser.Id };
            }

            if (ModelState.IsValid)
            {
                try
                {
                    AnnouncementType type = AnnouncementType.AdministrationEventAnnounce;
                    //盘点任务
                    if (model.BusinessType == BusinessType.AssetInventory)
                    {
                        type = AnnouncementType.AssetInventory;
                    }

                    var annocumentModel = new AnnouncementModel()
                    {
                        Type          = type,
                        Title         = model.Title,
                        Content       = model.MessageContent,
                        ApplyUserId   = CommonInstance.GetInstance().LoginUser.Id,
                        EffectiveDays = 30,
                        CreateUserId  = CommonInstance.GetInstance().LoginUser.Id,
                        CreatedTime   = DateTime.Now,
                        Status        = AnnouncementStatus.AllowPublish,
                    };
                    this.AnnouncementService.AddAnnouncement(annocumentModel);
                    //if (model.BusinessType == BusinessType.AssetInventory)
                    //{
                    //    int inventoryId = this.AssetInventoryService.AddAssetInventory(new AssetInventoryModel()
                    //    {
                    //        Title = model.Title,
                    //        Description = model.MessageContent,
                    //        Status = AssetInventoryStatus.Open
                    //    });
                    //    model.MessagePrams = inventoryId.ToString();
                    //}
                    //bool isProduction = false;
                    //if (ConfigurationManager.AppSettings["IsProduction"] != null && ConfigurationManager.AppSettings["IsProduction"].ToLower() == "true")
                    //{
                    //    isProduction = true;
                    //}
                    //this.NotificationService.Add(model, isProduction);
                    ////资产盘点发通知后需要创建新的盘点任务

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }

            return(View(model));
        }
        public ActionResult Edit(AnnouncementModel model)
        {
            string action = Request["Submit"];

            if (action == "cancel")
            {
                return(RedirectToAction("Index"));
            }

            if (string.IsNullOrEmpty(model.Title))
            {
                ModelState.AddModelError("Title", "请输入标题.");
            }

            if (string.IsNullOrEmpty(model.Content))
            {
                ModelState.AddModelError("Content", "请输入通知内容.");
            }
            if (model.EffectiveDays == null || model.EffectiveDays == 0)
            {
                ModelState.AddModelError("EffectiveDays", "请输入有效天数.");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var annocumentModel = new AnnouncementModel()
                    {
                        Type                = model.Type,
                        Title               = model.Title,
                        Content             = model.Content,
                        ApplyUserId         = CommonInstance.GetInstance().LoginUser.Id,
                        EffectiveDays       = model.EffectiveDays,
                        CreateUserId        = CommonInstance.GetInstance().LoginUser.Id,
                        CreatedTime         = DateTime.Now,
                        Status              = AnnouncementStatus.AllowPublish,
                        RefAssetInventoryId = 0
                    };
                    this.AnnouncementService.AddAnnouncement(annocumentModel);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }
            var businessTypeList = new List <SelectListItem>();

            businessTypeList.Add(new SelectListItem()
            {
                Text  = "公告通知",
                Value = ((int)AnnouncementType.AdministrationEventAnnounce).ToString()
            });
            businessTypeList.Add(new SelectListItem()
            {
                Text  = "资产盘点",
                Value = ((int)AnnouncementType.AssetInventory).ToString()
            });
            businessTypeList.Add(new SelectListItem()
            {
                Text  = "活动消息",
                Value = ((int)AnnouncementType.ActivityMessage).ToString()
            });
            businessTypeList.Add(new SelectListItem()
            {
                Text  = "公司消息",
                Value = ((int)AnnouncementType.CompanyNews).ToString()
            });
            businessTypeList.Add(new SelectListItem()
            {
                Text  = "员工消息",
                Value = ((int)AnnouncementType.EmployeeeNews).ToString()
            });
            ViewData["businessTypeList"] = new SelectList(businessTypeList, "Value", "Text", (int)model.Type);
            return(View(model));
        }