示例#1
0
        public ActionResult DeleteCustomer(Guid id)
        {
            var oldData = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(id));
            var response = ServiceHelper.Customer.ExecuteDispose(s => s.DeleteCustomer(id, PhysicalDataImagesFolderPath));

            if (response.Success)
            {
                #region Log

                var dataLog = new DataLog
                {
                    BeUserId = CurrentUserId,
                    Table = TableLog.Customer,
                    Action = ActionLog.Delete,
                    LogDate = DateTime.UtcNow,
                    OldData = ObjectToLog(oldData),
                    ItemId = id
                };

                ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest
                {
                    Entity = dataLog
                }));

                #endregion

                return JsonObject(true, BackendMessage.DeleteSuccessfull);
            }

            return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
        }
示例#2
0
        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());
        }
示例#3
0
        public ActionResult SaveImage(Guid customerId)
        {
            var imagePath = string.Empty;

            #region save image

            if (Request.Files["fileImage"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage"].FileName))
            {
                var file = Request.Files["fileImage"];

                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);
                }

                imagePath = Guid.NewGuid() + extension;

                var filePath = PhysicalDataFilePath(imagePath);
                file.SaveAs(filePath);
            }

            #endregion

            var oldData = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(customerId));

            if (oldData == null)
            {
                return JsonObject(false, BackendMessage.CannotLoadData);
            }

            var customerImage = new CustomerImage
            {
                ImagePath = imagePath,
                CustomerId = customerId,
                CreatedDate = DateTime.UtcNow
            };

            customerImage.InitId();

            var response = ServiceHelper.Customer.ExecuteDispose(s => s.SaveImage(customerImage));

            if (response.Success)
            {
                var customer = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(customerId));
                if (customer == null)
                {
                    return JsonObject(false, BackendMessage.CannotLoadData);
                }

                #region Log

                var dataLog = new DataLog
                {
                    BeUserId = CurrentUserId,
                    Table = TableLog.Customer,
                    Action = ActionLog.InsertImage,
                    LogDate = DateTime.UtcNow,
                    NewData = ObjectToLog(customer),
                    OldData = ObjectToLog(oldData),
                    ItemId = customerId
                };

                ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest
                {
                    Entity = dataLog
                }));

                #endregion

                return JsonObject(true, BackendMessage.SaveDataSuccess, new
                {
                    imageList = PartialViewToString("BaseView/Customer/ImageList/_imageList", customer.Map<Customer, CustomerModel>())
                });
            }

            return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
        }
示例#4
0
        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());
        }
示例#5
0
        public ActionResult ImportCustomers()
        {
            var file = Request.Files["fileImport"];
            if (file == null || string.IsNullOrWhiteSpace(file.FileName))
            {
                return JsonObject(false, BackendMessage.DataInvalid);
            }

            var fileName = Path.GetFileName(file.FileName);

            var localFilePath = PhysicalDataFilePath(Guid.NewGuid() + Path.GetExtension(fileName), DataChildFolder.Files);

            if (!SiteUtils.IsExcelFile(fileName))
            {
                return JsonObject(false, BackendMessage.ExcelFileInvalid);
            }

            try
            {
                file.SaveAs(localFilePath);

                var table = LoadExcelFile(localFilePath);

                if (table == null || table.Rows.Count == 0)
                {
                    DeleteFile(localFilePath);
                    return JsonObject(false, BackendMessage.ThereIsNoDataRows);
                }

                if (table.Columns.Count != 22)
                {
                    DeleteFile(localFilePath);
                    return JsonObject(false, BackendMessage.ThereIsNotEnoughColumns);
                }

                //Check : must be have header row
                if (!CheckHaveHeaderRow(table))
                {
                    DeleteFile(localFilePath);
                    return JsonObject(false, BackendMessage.HeaderRowInvalid);
                }

                // Remove end empty row
                RemoveLastEmptyRow(table);

                //Check required field
                var listMessge = CheckInfoRequired(table);

                // Check email is valid format
                listMessge.AddRange(CheckEmailValidFormat(table));

                if (listMessge.Any())
                {
                    DeleteFile(localFilePath);
                    return JsonObject(false, string.Join("<br/>", listMessge));
                }

                //Save
                var listCustomer = new List<Customer>();
                PopulateSaveImportData(listCustomer, table);

                DeleteFile(localFilePath);

                var response = ServiceHelper.Customer.ExecuteDispose(s => s.SaveCustomers(listCustomer));

                if (response.Success)
                {
                    #region Log

                    listCustomer.ForEach(customer =>
                    {
                        var dataLog = new DataLog
                        {
                            BeUserId = CurrentUserId,
                            Table = TableLog.Customer,
                            Action = ActionLog.Insert,
                            LogDate = DateTime.UtcNow,
                            NewData = ObjectToLog(customer),
                            ItemId = customer.Id
                        };

                        ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest
                        {
                            Entity = dataLog
                        }));
                    });

                    #endregion

                    return JsonObject(true, BackendMessage.ImportDataSuccessfull);
                }

                return JsonObject(false, GetMessageFromList(response.Messages));
            }
            catch (Exception e)
            {
                DeleteFile(localFilePath);
                return JsonObject(false, e.Message);
            }
        }
示例#6
0
        public ActionResult DeleteImage(Guid id, Guid customerId)
        {
            var oldData = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(customerId));

            if (oldData == null)
            {
                return JsonObject(false, BackendMessage.CannotLoadData);
            }

            var response = ServiceHelper.Customer.ExecuteDispose(s => s.DeleteImage(id, PhysicalDataImagesFolderPath));

            if (response.Success)
            {
                var customer = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(customerId));

                if (customer == null)
                {
                    return JsonObject(false, BackendMessage.CannotLoadData);
                }
                #region Log

                var dataLog = new DataLog
                {
                    BeUserId = CurrentUserId,
                    Table = TableLog.Customer,
                    Action = ActionLog.DeleteImage,
                    LogDate = DateTime.UtcNow,
                    NewData = ObjectToLog(customer),
                    OldData = ObjectToLog(oldData),
                    ItemId = customerId
                };

                ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest
                {
                    Entity = dataLog
                }));

                #endregion

                return JsonObject(true, BackendMessage.DeleteSuccessfull, new
                {
                    imageList = PartialViewToString("BaseView/Customer/ImageList/_imageList", customer.Map<Customer, CustomerModel>())
                });
            }

            return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
        }
示例#7
0
        public ActionResult DeleteCustomers(string ids)
        {
            var arrId = ids.ToStr().Split(new[] { "#" }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToGuid()).ToList();
            if (!arrId.Any())
            {
                return JsonObject(false, BackendMessage.DataInvalid);
            }

            foreach (var id in arrId)
            {
                var customerId = id;
                var oldData = ServiceHelper.Customer.ExecuteDispose(s => s.GetCustomer(customerId));
                var response = ServiceHelper.Customer.ExecuteDispose(s => s.DeleteCustomer(customerId, PhysicalDataImagesFolderPath));
                if (!response.Success)
                {
                    return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
                }

                #region Log

                var dataLog = new DataLog
                {
                    BeUserId = CurrentUserId,
                    Table = TableLog.Customer,
                    Action = ActionLog.Delete,
                    LogDate = DateTime.UtcNow,
                    OldData = ObjectToLog(oldData),
                    ItemId = id
                };

                ServiceHelper.DataLog.ExecuteDispose(s => s.Insert(new Data.DataContract.DataLogDC.SaveRequest
                {
                    Entity = dataLog
                }));

                #endregion
            }

            return JsonObject(true, BackendMessage.DeleteSuccessfull);
        }