//Lấy chi tiết gói cước của khách hàng public CustomerServicePlanDetailModel GetCustomerServicePlanDetail(int id) { try { CustomerServicePlanDetailModel data = new CustomerServicePlanDetailModel(); CustomerServicePlan c = cnn.CustomerServicePlans.Find(id); data.ID = c.ID; data.Code = c.code; data.CusName = c.Customer.Name; data.ServiceName = c.Order.ServicePlan.Name; data.LocaRequest = !String.IsNullOrEmpty(c.Address) ? c.Customer.Village.Name + " " + c.Customer.District.Name + " " + c.Customer.Province.Name : c.Address; data.ActiveDate = c.ActiveDate; data.Status = c.Status.Value; data.histories = c.HistoryCustomerServicePlans.Where(h => h.IsActive.Equals(SystemParam.ACTIVE)).Select(h => new HistoryCustomerServicePlan { Note = h.Note, Status = h.Status, CreatedDate = h.CreatedDate }).OrderByDescending(h => h.ID).ToList(); return(data); } catch { return(new CustomerServicePlanDetailModel()); } }
public JsonResult UpdateCustomerServicePlan(CustomerServicePlanDetailModel input) { if (admin.Role.Equals(SystemParam.ROLE_TECHNICAL_STAFF)) { HttpResponseBase response = Response; response.Redirect("/ServicePlanManage/Index"); } input.UserID = admin.Id; return(Json(customerServicePlan.UpdateCustomerServicePlan(input), JsonRequestBehavior.AllowGet)); }
//Cập nhật thông tin gói cước của khách hàng public JsonResultModel UpdateCustomerServicePlan(CustomerServicePlanDetailModel input) { try { CustomerServicePlan c = cnn.CustomerServicePlans.Find(input.ID); HistoryCustomerServicePlan h = new HistoryCustomerServicePlan(); string content = ""; switch (input.Type) { //Cập nhật trạng thái của gói cước case 1: if (!input.Status.Equals(c.Status.Value)) { switch (input.Status) { case SystemParam.NO_ACTIVE_STATUS: //Lưu lại lịch sử gói cước h.UserID = input.UserID; h.Note = !String.IsNullOrEmpty(input.Note) ? input.Note : ""; h.IsActive = SystemParam.ACTIVE; h.CustomerServicePlanID = c.ID; h.Status = input.Status; h.CreatedDate = DateTime.Now; cnn.HistoryCustomerServicePlans.Add(h); content = "Gói cước " + c.Order.ServicePlan.Name + " của bạn đã bị ngừng hoạt động"; break; case SystemParam.ACTIVE_STATUS: h.UserID = input.UserID; h.Note = !String.IsNullOrEmpty(input.Note) ? input.Note : ""; h.CustomerServicePlanID = c.ID; h.IsActive = SystemParam.ACTIVE; h.Status = input.Status; h.CreatedDate = DateTime.Now; cnn.HistoryCustomerServicePlans.Add(h); content = "Gói cước " + c.Order.ServicePlan.Name + " của bạn đã được hoạt động trở lại"; break; default: break; } } c.Status = input.Status; break; //Gia gạn thêm cho gói cước case 2: c.Status = SystemParam.ACTIVE_STATUS; h.UserID = input.UserID; h.Note = !String.IsNullOrEmpty(input.Note) ? input.Note : ""; h.IsActive = SystemParam.ACTIVE; h.CreatedDate = DateTime.Now; cnn.HistoryCustomerServicePlans.Add(h); c.ExtendDate = DateTime.Now; h.CustomerServicePlanID = c.ID; h.Status = SystemParam.ACTIVE_STATUS; c.ExpiryDate = DateTime.Now.AddMonths(c.Order.ServicePlan.Value); h.Status = SystemParam.ACTIVE_STATUS; content = "Gói cước " + c.Order.ServicePlan.Name + " của bạn đã được gia hạn thêm"; break; default: break; } cnn.SaveChanges(); if (!String.IsNullOrEmpty(content)) { email.configClient(c.Customer.Email, "[NEXUS SYSTEM THÔNG BÁO]", content); } return(rp.response(SystemParam.SUCCESS, SystemParam.SUCCESS_CODE, "Thành công", "")); } catch (Exception e) { e.ToString(); return(rp.serverError()); } }