public async Task <object> Put(string id, [FromBody] HotelComment model) { var obj = hostelContext.PersonEmploys.FirstOrDefault(d => d.GUID == id); if (obj != null) { obj.Status = 0; obj.Evaluate = model.Evaluate; obj.Comment = model.Comment; } try { hostelContext.PersonOrders.RemoveRange(hostelContext.PersonOrders.Where(d => d.PersonId == obj.PersonId)); var person = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == obj.PersonId); var order = hostelContext.HotelOrders.Where(d => d.Id == obj.HotelOrderId).Select(d => new { HotelName = d.Hotel.Name, HotelGUID = d.Hotel.GUID, HotelDepartment = d.Department.DepartmentName, HotelWork = d.WorkType.Name }).FirstOrDefault(); hostelContext.Messages.Add(new HostelModel.MessageModel() { Context = $"{order.HotelName} 于 {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 终止 了您的{order.HotelDepartment}-{order.HotelWork}的工作!", From = order.HotelGUID, To = person?.GUID, Type = "工作终止" }); hostelContext.SaveChanges(); NoticeCommon notice = new NoticeCommon(options); await notice.SendNotice(new MessageWeb.Models.NoticeModel() { Type = "解聘", Phone = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == obj.PersonId)?.Phone, Hotel = hostelContext.HotelOrders.FirstOrDefault(d => d.Id == obj.HotelOrderId)?.Hotel?.Name ?? "酒店" }); return(new { state = true, message = "操作成功" }); } catch (Exception) { return(new { state = false, message = "数据操作服务器错误,请确认数据是否完整" }); } }
public async Task <object> Put(string id, [FromBody] HotelOrderStatusModel model) { var obj = hostelContext.PersonOrders.FirstOrDefault(d => d.GUID == id); if (model.Status == 3) //用户已经被录用后不能被其他酒店录用 { var count = hostelContext.PersonEmploys.Count(d => d.PersonId == model.PersonId && d.Status == 1); if (count > 0) { return(new { state = false, message = "用户已经被其他酒店录用" }); } hostelContext.PersonEmploys.Add(new PersonEmployModel() { HotelOrderId = model.OrderId, PersonId = model.PersonId, Status = 1, }); } if (obj != null) { obj.Status = model.Status; if (obj.Status == 2 || obj.Status == 3) { NoticeCommon notice = new NoticeCommon(options); var orderDatail = hostelContext.HotelOrders.Include(d => d.Hotel).Include(d => d.Department).Include(d => d.WorkType).FirstOrDefault(d => d.Id == model.OrderId); var person = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == obj.PersonId); var order = hostelContext.HotelOrders.Where(d => d.Id == obj.OrderId).Select(d => new { HotelName = d.Hotel.Name, HotelGUID = d.Hotel.GUID, HotelDepartment = d.Department.DepartmentName, HotelWork = d.WorkType.Name }).FirstOrDefault(); string statsStr = obj.Status == 2 ? "预录用" : "录用"; hostelContext.Messages.Add(new HostelModel.MessageModel() { Context = $"{order?.HotelName} 于 {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} {statsStr} 您的{order?.HotelDepartment}-{order?.HotelWork}工作!", From = order?.HotelGUID, To = person?.GUID, Type = "工作状态变更" }); await notice.SendNotice(new MessageWeb.Models.NoticeModel() { Type = statsStr, Phone = hostelContext.ServicePersons.FirstOrDefault(d => d.Id == model.PersonId)?.Phone, Title = $"{orderDatail?.HotelName}-{orderDatail?.DepartName}-{orderDatail?.WorkTypeName}" }); } //对于录用状态删除其余申请记录 if (obj.Status == 3) { hostelContext.PersonOrders.RemoveRange(hostelContext.PersonOrders.Where(d => d.Id != obj.Id && d.PersonId == obj.PersonId)); } } try { hostelContext.SaveChanges(); return(new { state = true, message = "操作成功" }); } catch (Exception) { return(new { state = false, message = "数据操作服务器错误,请确认数据是否完整" }); } }