public JsonResult Create(RestDto dto) { var res = _restContract.Insert(dto); return(Json(res)); }
public JsonResult Create(string AdminIds, RestDto dto) { OperationResult oper; try { string strDay = ConfigurationHelper.GetAppSetting("RestDay"); int day = int.Parse(strDay); //Rest rest = _restContract.Rests.Where(x => x.AdminId == dto.AdminId && x.IsEnabled == true && x.IsDeleted == false).FirstOrDefault(); if (AdminIds == null || string.IsNullOrEmpty(AdminIds)) { return(Json(oper = new OperationResult(OperationResultType.Error, "请选择员工或部门"))); } List <int> adminIds = AdminIds.Split(',').Select(a => int.Parse(a)).ToList(); int error = 0; OperationResult oper_single = null; foreach (var id in adminIds) { Administrator admin = _administratorContract.Administrators.FirstOrDefault(a => a.Id == id); if (admin == null) { oper_single = new OperationResult(OperationResultType.Error, "该用户不存在"); error++; continue; } Rest rest = _restContract.Rests.Where(x => x.AdminId == admin.Id && x.IsEnabled == true && x.IsDeleted == false).FirstOrDefault(); if (rest == null) { dto.AdminId = admin.Id; dto.RealName = admin.Member.RealName; if (day < dto.PaidLeaveDays) { oper_single = new OperationResult(OperationResultType.Error, "最多奖励" + strDay + "天"); error++; continue; } oper_single = _restContract.Insert(dto); } else { double restDay = rest.PaidLeaveDays + dto.PaidLeaveDays; if (restDay > day) { oper_single = new OperationResult(OperationResultType.Error, "超过最多奖励" + strDay + "天"); error++; continue; } rest.PaidLeaveDays = restDay; rest.UpdatedTime = DateTime.Now; oper_single = _restContract.Update(rest); } if (oper_single.ResultType == OperationResultType.Error) { error++; } } if (error == 0) { oper = new OperationResult(OperationResultType.Success, "添加成功"); } else if (error == adminIds.Count()) { oper = new OperationResult(OperationResultType.Error, "添加失败"); } else { oper = new OperationResult(OperationResultType.Success, "添加成功" + (adminIds.Count() - error) + "条,失败" + error + "条"); } return(Json(oper)); } catch (Exception ex) { _Logger.Error <string>(ex.ToString()); oper = new OperationResult(OperationResultType.Error, "服务器忙,请稍后重试"); return(Json(oper)); } }