public ActionResult Add() { ViewBag.AddNewTitle = AddNewTitle; var model = new CustomerModel { CustomerType = CustomerType }; PopulateVisitIndexModel(model); PopulateCustomerServiceIndexModel(model); PopulateDataLogIndexModel(model); return View(editViewName, model); }
public ActionResult UpdateCustomerType(CustomerModel model) { var customer = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(model.Id)); if (customer == null) { return JsonObject(false, BackendMessage.CannotLoadData); } var response = ServiceHelper.Customer.UpdateInfo(customer, new UpdateInfo { CustomerType = model.CustomerType }); if (response.Success) { #region Log var newData = customer.Clone(); newData.CustomerType = model.CustomerType; var dataLog = new DataLog { BeUserId = CurrentUserId, Table = TableLog.Customer, Action = ActionLog.ChangeType, LogDate = DateTime.UtcNow, NewData = ObjectToLog(newData), OldData = ObjectToLog(customer), ItemId = customer.Id }; ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest { Entity = dataLog })); #endregion return JsonObject(true, BackendMessage.SaveDataSuccess); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public ActionResult SaveCustomer(CustomerModel model) { if (model.IsNew && !CanAdd) { return GetAddDeniedResult(); } if (!model.IsNew && !CanUpdate) { return GetUpdateDeniedResult(); } ModelState.Remove("City"); ModelState.Remove("District"); if (!ModelState.IsValid && GetModelStateErrorList().Any()) { return JsonObject(false, GetModelStateErrors()); } #region fill working hours DateTime dateTime; if (!string.IsNullOrWhiteSpace(model.SundayStartStr)) { dateTime = DateTime.Parse(model.SundayStartStr, CultureInfo.CurrentCulture); model.SundayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.SundayEndStr)) { dateTime = DateTime.Parse(model.SundayEndStr, CultureInfo.CurrentCulture); model.SundayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //--- if (!string.IsNullOrWhiteSpace(model.MondayStartStr)) { dateTime = DateTime.Parse(model.MondayStartStr, CultureInfo.CurrentCulture); model.MondayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.MondayEndStr)) { dateTime = DateTime.Parse(model.MondayEndStr, CultureInfo.CurrentCulture); model.MondayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //-- if (!string.IsNullOrWhiteSpace(model.TuesdayStartStr)) { dateTime = DateTime.Parse(model.TuesdayStartStr, CultureInfo.CurrentCulture); model.TuesdayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.TuesdayEndStr)) { dateTime = DateTime.Parse(model.TuesdayEndStr, CultureInfo.CurrentCulture); model.TuesdayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //--- if (!string.IsNullOrWhiteSpace(model.WednesdayStartStr)) { dateTime = DateTime.Parse(model.WednesdayStartStr, CultureInfo.CurrentCulture); model.WednesdayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.WednesdayEndStr)) { dateTime = DateTime.Parse(model.WednesdayEndStr, CultureInfo.CurrentCulture); model.WednesdayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //--- if (!string.IsNullOrWhiteSpace(model.ThursdayStartStr)) { dateTime = DateTime.Parse(model.ThursdayStartStr, CultureInfo.CurrentCulture); model.ThursdayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.ThursdayEndStr)) { dateTime = DateTime.Parse(model.ThursdayEndStr, CultureInfo.CurrentCulture); model.ThursdayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //--- if (!string.IsNullOrWhiteSpace(model.FridayStartStr)) { dateTime = DateTime.Parse(model.FridayStartStr, CultureInfo.CurrentCulture); model.FridayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.FridayEndStr)) { dateTime = DateTime.Parse(model.FridayEndStr, CultureInfo.CurrentCulture); model.FridayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } //--- if (!string.IsNullOrWhiteSpace(model.SaturdayStartStr)) { dateTime = DateTime.Parse(model.SaturdayStartStr, CultureInfo.CurrentCulture); model.SaturdayStart = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } if (!string.IsNullOrWhiteSpace(model.SaturdayEndStr)) { dateTime = DateTime.Parse(model.SaturdayEndStr, CultureInfo.CurrentCulture); model.SaturdayEnd = new DateTime(ConstKeys.YearForTime, ConstKeys.MonthForTime, ConstKeys.DayForTime, dateTime.Hour, dateTime.Minute, 0); } #endregion #region visit var jsonSerializer = new JavaScriptSerializer(); model.Visits = jsonSerializer.Deserialize<List<CustomerVisitModel>>(model.VisitJsonString); model.CustomerServices = jsonSerializer.Deserialize<List<CustomerServiceModel>>(model.CustomerServiceJsonString); #endregion #region save list image var listImagePath = new List<string>(); for (var i = 0; i < Request.Files.Count; ++i) { var file = Request.Files[i]; if (file != null && !string.IsNullOrWhiteSpace(file.FileName)) { var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } var imagePath = Guid.NewGuid() + extension; listImagePath.Add(imagePath); var filePath = PhysicalDataFilePath(imagePath); file.SaveAs(filePath); } } #endregion var entity = model.Map<CustomerModel, Customer>(); var oldData = new Customer(); entity.UpdatedDate = DateTime.UtcNow; entity.UpdatedBy = CurrentUserId; if (entity.IsNew) { entity.InitId(); entity.CreatedDate = DateTime.UtcNow; entity.CreatedBy = CurrentUserId; } else { oldData = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(entity.Id)); if (oldData == null) { return JsonObject(false, BackendMessage.CannotLoadData); } entity.CreatedDate = oldData.CreatedDate; entity.CreatedBy = oldData.CreatedBy; } entity.Visits.ForEach(i => i.CustomerId = entity.Id); entity.CustomerServices.ForEach(i => i.CustomerId = entity.Id); var response = ServiceHelper.Customer.ExecuteDispose(s => s.SaveCustomer(new SaveRequest { Entity = entity })); if (response.Success) { if (listImagePath.Any()) { var listImages = new List<CustomerImage>(); listImagePath.ForEach(imagePath => { var image = new CustomerImage { ImagePath = imagePath, CustomerId = entity.Id, CreatedDate = DateTime.UtcNow }; image.InitId(); listImages.Add(image); }); ServiceHelper.Customer.ExecuteDispose(s => s.SaveListImage(listImages)); } SendNotification(NotifyType.Success, BackendMessage.SaveDataSuccess); #region Log var dataLog = new DataLog { BeUserId = CurrentUserId, Table = TableLog.Customer, Action = model.IsNew ? ActionLog.Insert : ActionLog.Update, LogDate = DateTime.UtcNow, NewData = ObjectToLog(entity), OldData = model.IsNew ? string.Empty : ObjectToLog(oldData), ItemId = entity.Id }; ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest { Entity = dataLog })); #endregion return JsonObject(true, string.Empty); } if (listImagePath.Any()) { listImagePath.ForEach(DeleteImageFile); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public ActionResult GetDropDownDistrictsWards(CustomerModel model) { return JsonObject(true, string.Empty, new { dropDownDistrict = PartialViewToString("BaseView/Customer/Edit/_dropDownDistrict", model) }); }
public ActionResult GetVisits(CustomerModel model) { PopulateVisitIndexModel(model); return JsonObject(true, string.Empty, new { html = PartialViewToString("BaseView/Customer/Edit/_visit", model.VisitIndex) }); }
public ActionResult GetDataLogs(CustomerModel model) { PopulateDataLogIndexModel(model); return JsonObject(true, string.Empty, new { html = PartialViewToString("BaseView/Customer/Inc/_dataLog", model.DataLogIndex) }); }
public ActionResult GetCustomerServices(CustomerModel model) { PopulateCustomerServiceIndexModel(model); return JsonObject(true, string.Empty, new { html = PartialViewToString("BaseView/Customer/Edit/_customerService", model.CustomerServiceIndex) }); }
public ActionResult EditVisit(CustomerModel model, Guid? id) { ModelState.Clear(); var visitModel = new CustomerVisitModel { BeUserId = CurrentUserId, DateVisit = DateTime.Today }; visitModel.InitId(); if (id.HasValue) { visitModel = model.Visits.FirstOrDefault(i => i.Id == id.Value); if (visitModel == null) { return JsonObject(false, BackendMessage.CannotLoadData); } } return JsonObject(true, string.Empty, new { html = PartialViewToString("BaseView/Customer/Edit/_editVisit", visitModel) }); }
protected void PopulateVisitIndexModel(CustomerModel model) { model.Visits.Where(i => i.IsNew).ForEach(i => i.InitId()); model.VisitIndex.Results = model.Visits; model.VisitIndex.InitSortInfo(); if (string.IsNullOrWhiteSpace(model.VisitIndex.SortBy)) { model.VisitIndex.SortBy = "DateVisit"; } var pageOption = new PageOption { PageSize = model.VisitIndex.Pagination.PageSize, PageNumber = model.VisitIndex.Pagination.CurrentPageIndex }; if (model.VisitIndex.SortBy == "DateVisit") { if (model.VisitIndex.SortDirection.HasValue) { model.VisitIndex.Results = model.VisitIndex.SortDirection.Value == SortDirection.Asc ? model.VisitIndex.Results.OrderBy(i => i.DateVisit).ToList() : model.VisitIndex.Results.OrderByDescending(i => i.DateVisit).ToList(); model.VisitIndex.Pagination.TotalRecords = model.VisitIndex.Results.Count(); } else { model.VisitIndex.Results = model.VisitIndex.Results.OrderBy(i => i.DateVisit).ToList(); model.VisitIndex.Pagination.TotalRecords = model.VisitIndex.Results.Count(); } } if (pageOption.IsValid) { model.VisitIndex.Results = model.VisitIndex.Results.Skip(pageOption.PageStartIndex).Take(pageOption.PageSize).ToList(); } }
protected void PopulateDataLogIndexModel(CustomerModel customerModel) { var model = customerModel.DataLogIndex; if (!model.SortDirection.HasValue) { model.SortDirection = SortDirection.Desc; } model.InitSortInfo(); if (string.IsNullOrWhiteSpace(model.SortBy)) { model.SortBy = "LogDate"; } var filter = new Data.DataContract.DataLogDC.FindRequest { Table = TableLog.Customer, ItemId = customerModel.Id, SortOption = new SortOption(new[] { new SortItem(model.SortBy, model.SortDirection.Value) }), //PageOption = new PageOption { PageSize = model.Pagination.PageSize, PageNumber = model.Pagination.CurrentPageIndex } PageOption = new PageOption { PageSize = int.MaxValue, PageNumber = model.Pagination.CurrentPageIndex } }; var response = ServiceHelper.DataLog.ExecuteDispose(s => s.FindDataLogs(filter)); model.Results = response.Results.MapList<DataLogModel>(); model.Pagination.TotalRecords = response.TotalRecords; }