/// <summary> /// 修改密码 /// </summary> /// <param name="newPassword">新密码</param> /// <param name="userID">用户ID</param> /// <returns></returns> public bool ModifyPassword(string newPassword, string oldPassword, int userID) { var user = GetUser(userID); if (user != null && user.Password == oldPassword) { return(_workingDB.Execute("update users set password=@password where id=@id", new { password = newPassword, id = userID }) > 0); } else { throw new Exception($"修改密码:修改密码失败:旧密码不正确"); } }
/// <summary> /// 添加工作记录 /// </summary> /// <param name="workItem">工作记录</param> /// <returns></returns> public bool AddWorkItem(WorkItem workItem, int userID) { var beginDay = DateTime.Parse($"{workItem.RecordDate.ToShortDateString()} 00:00:00.000"); var endDay = DateTime.Parse($"{workItem.RecordDate.ToShortDateString()} 23:59:59.999"); var count = _workingDB.Query <WorkItem>("select * from workitems where recorddate>=@begindt and recorddate<=@enddt and createuserid=@userid", new { begindt = beginDay, enddt = endDay, userid = userID }).Count(); if (count == 0) { return(_workingDB.Execute("insert into workitems(createtime,createuserid,recorddate,workcontent,memos) values(@createtime,@createuserid,@recorddate,@workcontent,@memos)", new { createtime = DateTime.Now, createuserid = userID, recorddate = workItem.RecordDate, workcontent = workItem.WorkContent, memos = workItem.Memos }) > 0); } else { return(_workingDB.Execute("update workitems set createtime=@createtime,createuserid=@createuserid,recorddate=@recorddate,workcontent=@workcontent,memos=@memos where id=@id", new { createtime = DateTime.Now, createuserid = userID, recorddate = workItem.RecordDate, workcontent = workItem.WorkContent, memos = workItem.Memos, id = workItem.ID }) > 0); } }
/// <summary> /// 添加部门 /// </summary> /// <param name="department">部门</param> /// <returns></returns> public bool AddDepartment(Department department) { return(_workingDB.Execute("insert into departments(departmentname,pdepartmentid) values(@departmentname,@pdepartmentid)", new { departmentname = department.DepartmentName, pdepartmentid = department.PDepartmentID }) > 0); }