public async Task <ActionResult> Update(HosoCorrierRequestModel model) { if (model == null || model.Id <= 0) { return(ToResponse(false, "Dữ liệu không hợp lệ")); } if (string.IsNullOrWhiteSpace(model.CustomerName)) { return(ToResponse(false, "Tên khách hàng không được để trống")); } if (model.AssignId <= 0) { return(ToResponse(false, "Vui lòng chọn courier")); } var profile = await _rpCourierProfile.GetById(model.Id); if (profile == null) { return(ToJsonResponse(false, "Hồ sơ không tồn tại")); } bool isAdmin = await _rpEmployee.CheckIsAdmin(GlobalData.User.IDUser); if (profile.Status == (int)TrangThaiHoSo.Cancel) { if (!isAdmin) { return(ToJsonResponse(false, "Bạn không có quyền, vui lòng liên hệ Admin")); } } var sale = null as OptionSimple; var hoso = new HosoCourier { CustomerName = model.CustomerName, Cmnd = model.Cmnd, Status = model.Status, LastNote = model.LastNote, UpdatedBy = GlobalData.User.IDUser, Phone = model.Phone, SaleCode = model.SaleCode, AssignId = model.AssignId, Id = model.Id, GroupId = model.GroupId, DistrictId = model.DistrictId, ProvinceId = model.ProvinceId }; var result = await _rpCourierProfile.Update(model.Id, hoso); if (result) { if (!string.IsNullOrWhiteSpace(model.SaleCode)) { if (sale != null) { await _rpCourierProfile.InsertCourierAssignee(model.Id, sale.Id); } } _rpCourierProfile.InsertCourierAssignee(model.Id, model.AssignId); if (!string.IsNullOrWhiteSpace(model.LastNote)) { var note = new GhichuModel { Noidung = model.LastNote, HosoId = model.Id, UserId = hoso.UpdatedBy, TypeId = (int)NoteType.HosoCourrier }; await _rpNote.AddNoteAsync(note); } } return(ToResponse(true)); }
public async Task <ActionResult> Create(HosoCorrierRequestModel model) { if (model == null) { return(ToResponse(false, "Dữ liệu không hợp lệ", 0)); } if (model.AssignId <= 0) { return(ToResponse(false, "Vui lòng chọn Courier", 0)); } var sale = await _rpEmployee.GetEmployeeByCode(model.SaleCode.ToString().Trim()); if (sale == null) { return(ToResponse(false, "Sale không tồn tại, vui lòng kiểm tra lại")); } var hoso = new HosoCourier { CustomerName = model.CustomerName, Cmnd = model.Cmnd, Status = (int)HosoCourierStatus.New, LastNote = model.LastNote, CreatedBy = GlobalData.User.IDUser, SaleCode = model.SaleCode, Phone = model.Phone, AssignId = model.AssignId, GroupId = model.GroupId, DistrictId = model.DistrictId, ProvinceId = model.ProvinceId }; var id = await _rpCourierProfile.Create(hoso); if (id > 0) { var tasks = new List <Task>(); var ids = new List <int>() { model.AssignId, GlobalData.User.IDUser, 1 }; //1 is Thainm if (!string.IsNullOrWhiteSpace(model.SaleCode)) { if (sale != null) { ids.Add(sale.Id); } } foreach (var assigneeId in ids) { tasks.Add(_rpCourierProfile.InsertCourierAssignee(id, assigneeId)); } await Task.WhenAll(tasks); if (!string.IsNullOrWhiteSpace(model.LastNote)) { var note = new GhichuModel { Noidung = model.LastNote, HosoId = id, UserId = hoso.CreatedBy, TypeId = (int)NoteType.HosoCourrier }; await _rpNote.AddNoteAsync(note); } return(ToResponse(true, "", id)); } return(ToResponse(false)); }