Example #1
0
        public virtual TEntity CreateMasterFile(MasterfileParameter parameters, Action <TViewModel> advanceMapping = null)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <TEntity>();
            var savedEntity = MasterFileService.Add(entity);

            return(savedEntity);
        }
Example #2
0
        public int Create(SystemConfigurationParameter parameters)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <SystemConfiguration>();
            var savedEntity = MasterFileService.Add(entity);

            return(savedEntity.Id);
        }
Example #3
0
        public int Create(ModuleParameter parameters)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <Module>();
            var savedEntity = MasterFileService.Add(entity);

            return(savedEntity.Id);
        }
Example #4
0
        public int Create(HoldingRequestParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <HoldingRequest>();

            entity.SendDate = entity.SendDate.GetValueOrDefault().ToUtcTimeFromClientTime();
            var savedEntity = MasterFileService.Add(entity);

            return(savedEntity.Id);
        }
Example #5
0
        public ActionResult Create(ScheduleParameter parameters)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <Schedule>();
            var savedEntity = MasterFileService.Add(entity);

            if (savedEntity.WarningInfo != null && !savedEntity.Confirm.GetValueOrDefault())
            {
                return(Json(new { savedEntity.Id, entity.WarningInfo, Error = "ErrorWarning" }, JsonRequestBehavior.DenyGet));
            }
            return(Json(new { savedEntity.Id }, JsonRequestBehavior.DenyGet));
        }
Example #6
0
        public JsonResult Create(LocationParameter parameters)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <Location>();
            var savedEntity = MasterFileService.Add(entity);

            return
                (Json(new
            {
                id = savedEntity.Id,
                name = savedEntity.Name
            }, JsonRequestBehavior.AllowGet));
        }
Example #7
0
        public ActionResult Create(UserRoleParameter parameters)
        {
            var viewModel      = MapFromClientParameters(parameters);
            var shareViewModel = viewModel.SharedViewModel as DashboardUserRoleShareViewModel;

            if (shareViewModel != null)
            {
                var listRoleFunctionUpdate = shareViewModel.CheckAll ? GetAllRoleFunction() : ProcessMappingFromUserRoleGrid(shareViewModel.UserRoleFunctionData);
                var listRoleFunctionOld    = new List <UserRoleFunction>();
                // Check user have edit some value in list role old => delete role old and add role new
                foreach (var oldItem in listRoleFunctionOld)
                {
                    if (listRoleFunctionUpdate.Any(o => o.DocumentTypeId == oldItem.DocumentTypeId))
                    {
                        oldItem.IsDeleted = true;
                    }
                }
                //after check user removed, remove item of the list new with conditions has property IsDelete equal true;

                //Copy listRoleFunctionUpdate
                var listRoleFunctionUpdateRecheck = listRoleFunctionUpdate.ToList();
                foreach (var item in listRoleFunctionUpdateRecheck.Where(item => item.IsDeleted))
                {
                    listRoleFunctionUpdate.Remove(item);
                }
                var objListFunctionForEntity = new List <UserRoleFunction>();
                // Add listUpdate
                objListFunctionForEntity.AddRange(listRoleFunctionUpdate);
                // Add list data in old
                foreach (var itemOld in listRoleFunctionOld.Where(o => !o.IsDeleted))
                {
                    var objAdd = new UserRoleFunction
                    {
                        DocumentTypeId      = itemOld.DocumentTypeId,
                        SecurityOperationId = itemOld.SecurityOperationId
                    };
                    objListFunctionForEntity.Add(objAdd);
                }
                var entity = shareViewModel.MapTo <UserRole>();
                entity.UserRoleFunctions = objListFunctionForEntity;
                var savedEntity = MasterFileService.Add(entity);
                MenuExtractData.Instance.RefershListData();
                return(Json(new { savedEntity.Id }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Id = 0 }, JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public JsonResult Create(CourierParameter parameters)
        {
            //get franchisee configuration
            var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
            var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
            {
                FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
            };
            var packageInfo    = _webApiConsumeUserService.GetListPackageChange(objFranchiseeAndLicense);
            var currentPackage = packageInfo.OrderByDescending(o => o.Id).Where(o => o.IsApply).FirstOrDefault();

            //Lay so luong courier dc cho phep cua franchisee
            int numberAllow = 2;

            if (currentPackage != null)
            {
                numberAllow = CaculatorHelper.GetNumberUserAllow(currentPackage.PackageId);
            }

            var numberOfUserCurrent = _userService.Count(o => o.UserRoleId == 2);

            if (numberAllow <= numberOfUserCurrent)
            {
                var mess = string.Format(SystemMessageLookup.GetMessage("NumberUserAllow"));
                MasterFileService.ThrowCustomValidation(mess);
            }
            //Bat dau Add
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <Courier>();

            entity.Status = (int)StatusCourier.Offline;
            // Generate password
            const string randomPassword = "******";

            if (entity.User.UserName != null)
            {
                entity.User.Password = PasswordHelper.HashString(randomPassword, entity.User.UserName);
            }

            var sharViewModel = viewModel.SharedViewModel as DashboardCourierShareViewModel;//
            var logoFilePath  = "";

            if (sharViewModel != null)
            {
                if (!String.IsNullOrEmpty(sharViewModel.UserShareViewModel.Avatar))
                {
                    if (!sharViewModel.UserShareViewModel.Avatar.Contains("data:image/jpg;base64"))
                    {
                        logoFilePath       = Server.MapPath(sharViewModel.UserShareViewModel.Avatar);
                        entity.User.Avatar = _resizeImage.ResizeImageByHeightAndWidth(logoFilePath, 450, 450);
                    }
                }
            }



            var savedEntity = MasterFileService.Add(entity);

            if (savedEntity.Id > 0)
            {
                var webLink       = AppSettingsReader.GetValue("Url", typeof(String)) as string;
                var imgSrc        = webLink + "/Content/quickspatch/img/logo-o.svg";
                var urlChangePass = webLink + "/Authentication/ChangePasswordCourier?code=" + PasswordHelper.HashString(savedEntity.Id.ToString(), entity.User.UserName);
                var fromEmail     = AppSettingsReader.GetValue("EmailFrom", typeof(String)) as string;
                var webapi        = AppSettingsReader.GetValue("WebApiUrlFranchisee", typeof(String)) as string;
                var displayName   = AppSettingsReader.GetValue("EmailFromDisplayName", typeof(String)) as string;
                //var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
                var franchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "";
                var emailContent   = Framework.Utility.TemplateHelpper.FormatTemplateWithContentTemplate(
                    TemplateHelpper.ReadContentFromFile(TemplateConfigFile.CreateCourierEmailTemplate, true),
                    new
                {
                    img_src         = imgSrc,
                    full_name       = Framework.Utility.CaculatorHelper.GetFullName(savedEntity.User.FirstName, savedEntity.User.MiddleName, savedEntity.User.LastName),
                    web_link        = webLink,
                    user_name       = entity.User.UserName,
                    password        = randomPassword,
                    url_change_pass = urlChangePass,
                    franchisee_Name = franchiseeName,
                    web_api         = webapi
                });
                // send email
                var logo = franchiseeConfiguration != null ? franchiseeConfiguration.Logo : new byte[0];
                _emailHandler.SendEmailSsl(fromEmail, new[] { savedEntity.User.Email }, SystemMessageLookup.GetMessage("SubjectToSendEmailForCreateUser"),
                                           emailContent, logo, true, displayName);
            }
            return
                (Json(new
            {
                id = savedEntity.Id,
                name =
                    Framework.Utility.CaculatorHelper.GetFullName(savedEntity.User.FirstName,
                                                                  savedEntity.User.MiddleName, savedEntity.User.LastName)
            }, JsonRequestBehavior.AllowGet));
        }
Example #9
0
        public int Create(UserParameter parameters)
        {
            //get franchisee configuration
            var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
            var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
            {
                FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
            };
            var packageInfo = _webApiConsumeUserService.GetListPackageChange(objFranchiseeAndLicense);

            //Bat dau Add
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <User>();
            // Generate password
            const string randomPassword = "******";

            if (entity.UserName != null)
            {
                entity.Password = PasswordHelper.HashString(randomPassword, entity.UserName);
            }
            //entity.Password = "******";
            var sharViewModel = viewModel.SharedViewModel as DashboardUserShareViewModel;//
            var logoFilePath  = "";

            if (sharViewModel != null)
            {
                if (!String.IsNullOrEmpty(sharViewModel.Avatar))
                {
                    if (!sharViewModel.Avatar.Contains("data:image/jpg;base64"))
                    {
                        logoFilePath  = Server.MapPath(sharViewModel.Avatar);
                        entity.Avatar = _resizeImage.ResizeImageByHeightAndWidth(logoFilePath, 450, 450);
                    }
                }
            }


            var savedEntity = MasterFileService.Add(entity);

            if (savedEntity.Id > 0)
            {
                var webLink       = AppSettingsReader.GetValue("Url", typeof(String)) as string;
                var urlSignIn     = webLink + "/Authentication/SignIn";
                var imgSrc        = webLink + "/Content/quickspatch/img/logo-o.svg";
                var urlChangePass = webLink + "/Authentication/ChangePassword?code=" + PasswordHelper.HashString(savedEntity.Id.ToString(), entity.UserName);
                var fromEmail     = AppSettingsReader.GetValue("EmailFrom", typeof(String)) as string;
                var displayName   = AppSettingsReader.GetValue("EmailFromDisplayName", typeof(String)) as string;
                //var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
                var franchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "";
                var emailContent   = Framework.Utility.TemplateHelpper.FormatTemplateWithContentTemplate(
                    TemplateHelpper.ReadContentFromFile(TemplateConfigFile.CreateUserEmailTemplate, true),
                    new
                {
                    img_src         = imgSrc,
                    full_name       = Framework.Utility.CaculatorHelper.GetFullName(savedEntity.FirstName, savedEntity.MiddleName, savedEntity.LastName),
                    web_link        = webLink,
                    user_name       = entity.UserName,
                    password        = randomPassword,
                    url_change_pass = urlChangePass,
                    franchisee_Name = franchiseeName,
                    url_sign_in     = urlSignIn
                });
                // send email
                var logo = franchiseeConfiguration != null ? franchiseeConfiguration.Logo : new byte[0];
                _emailHandler.SendEmailSsl(fromEmail, new[] { savedEntity.Email }, SystemMessageLookup.GetMessage("SubjectToSendEmailForCreateUser"),
                                           emailContent, logo, true, displayName);
            }
            return(savedEntity.Id);
        }
Example #10
0
        public ActionResult Create(RequestParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <Request>();

            if (entity.CourierId > 0)
            {
                var courier = _userService.GetById(entity.CourierId.GetValueOrDefault());
                if (courier.IsActive == false)
                {
                    throw new Exception("Cannot assign request to inactive courier");
                }
            }

            if (entity.IsStat == true)
            {
                entity.Status      = (int)StatusRequest.Sent;
                entity.SendingTime = DateTime.UtcNow;
            }
            else
            {
                entity.Status = (int)StatusRequest.NotSent;
            }
            entity.RequestNo = _staticValueService.GetNewRequestNumber();

            //Tinh estimate distance, estimate time
            var estimateDistance = 0;
            var estimateTime     = 0;

            if (entity.LocationFrom > 0 && entity.LocationTo > 0)
            {
                var fromLocation = _locationService.GetById(entity.LocationFrom);
                var fromPoint    = new GoogleMapPoint
                {
                    Lat = fromLocation.Lat.GetValueOrDefault(),
                    Lng = fromLocation.Lng.GetValueOrDefault()
                };

                var toLocation = _locationService.GetById(entity.LocationTo);
                var toPoint    = new GoogleMapPoint
                {
                    Lat = toLocation.Lat.GetValueOrDefault(),
                    Lng = toLocation.Lng.GetValueOrDefault()
                };
                var dataGoogle = _googleService.GetDistance(fromPoint, toPoint);
                if (dataGoogle.status == "OK")
                {
                    if (dataGoogle.rows[0].elements[0].status == "OK")
                    {
                        estimateDistance = dataGoogle.rows[0].elements[0].distance.value;
                        estimateTime     = dataGoogle.rows[0].elements[0].duration.value;
                    }
                }
            }

            entity.EstimateDistance = estimateDistance;
            entity.EstimateTime     = estimateTime;
            Request savedEntity;

            using (var transaction = new TransactionScope())
            {
                savedEntity = MasterFileService.Add(entity);
                if (viewModel.SharedViewModel is DashboardRequestShareViewModel)
                {
                    var holdingRequestId = ((DashboardRequestShareViewModel)viewModel.SharedViewModel).HoldingRequestId;
                    if (holdingRequestId.GetValueOrDefault() > 0)
                    {
                        _holdingRequestService.DeleteById(holdingRequestId.GetValueOrDefault());
                    }
                }
                transaction.Complete();
            }

            if (savedEntity != null)
            {
                return(Json(new { savedEntity.WarningInfo, savedEntity.Id }, JsonRequestBehavior.DenyGet));
            }
            return(Json(1, JsonRequestBehavior.DenyGet));
        }