public JsonResult SaveUserPrice(string MainID, string Data) { var list = JsonHelper.ToList(Data); var costInfo = this.GetEntityByID(MainID); if (costInfo == null) { throw new Formula.Exceptions.BusinessValidationException("未能找到指定的内容,无法添加个人单价"); } foreach (var item in list) { var userID = item.GetValue("UserID"); var entity = costInfo.S_HR_UserUnitPrice.FirstOrDefault(d => d.UserID == userID); if (entity == null) { entity = new S_HR_UserUnitPrice(); entity.ID = FormulaHelper.CreateGuid(); entity.UserID = item.GetValue("UserID"); entity.UserName = item.GetValue("UserName"); costInfo.S_HR_UserUnitPrice.Add(entity); } entity.UnitPrice = String.IsNullOrEmpty(item.GetValue("UnitPrice")) ? 0m : Convert.ToDecimal(item.GetValue("UnitPrice")); entity.UserLevel = item.GetValue("UserLevel"); } costInfo.ModifyDate = DateTime.Now; costInfo.ModifyUser = this.CurrentUserInfo.UserName; costInfo.ModifyUserID = this.CurrentUserInfo.UserID; this.entities.SaveChanges(); return(Json("")); }
public JsonResult SaveExcel() { var reader = new System.IO.StreamReader(HttpContext.Request.InputStream); string data = reader.ReadToEnd(); var tempdata = JsonConvert.DeserializeObject <Dictionary <string, string> >(data); var list = JsonConvert.DeserializeObject <List <S_HR_UserUnitPrice> >(tempdata["data"]); var currentUser = FormulaHelper.GetUserInfo(); string costInfoID = this.GetQueryString("CostInfoID"); var costInfo = this.GetEntityByID(costInfoID); if (costInfo == null) { throw new Formula.Exceptions.BusinessValidationException("未能找到指定的内容,无法添加个人单价"); } foreach (var item in list) { var employee = this.entities.Set <S_HR_Employee>().FirstOrDefault(d => d.Name == item.UserName); if (employee == null) { continue; } var userID = employee.UserID; var entity = costInfo.S_HR_UserUnitPrice.FirstOrDefault(d => d.UserID == userID); if (entity == null) { entity = new S_HR_UserUnitPrice(); entity.ID = FormulaHelper.CreateGuid(); entity.UserID = employee.UserID; entity.UserName = employee.Name; costInfo.S_HR_UserUnitPrice.Add(entity); } entity.UnitPrice = item.UnitPrice; entity.UserLevel = item.UserLevel; this.entities.SaveChanges(); } costInfo.ModifyDate = DateTime.Now; costInfo.ModifyUser = currentUser.UserName; costInfo.ModifyUserID = currentUser.UserID; return(Json("Success")); }