예제 #1
0
        public virtual TViewModel GetMasterFileViewModel(int id)
        {
            var entity    = MasterFileService.GetById(id);
            var viewModel = entity.MapTo <TViewModel>();

            return(viewModel);
        }
예제 #2
0
        public ActionResult Update(CourierParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);



            byte[] lastModified = null;
            var    logoFilePath = "";

            if (ModelState.IsValid)
            {
                var sharViewModel = viewModel.SharedViewModel as DashboardCourierShareViewModel;
                var entity        = MasterFileService.GetById(viewModel.SharedViewModel.Id);
                var mappedEntity  = viewModel.MapPropertiesToInstance(entity);

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

                lastModified = MasterFileService.Update(mappedEntity).LastModified;
            }

            return(Json(new { Error = string.Empty, Data = new { LastModified = lastModified } }, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public virtual JsonResult GetDataForGridMasterFile(QueryInfo queryInfo)
        {
            var queryData   = MasterFileService.GetDataForGridMasterfile(queryInfo);
            var clientsJson = Json(queryData, JsonRequestBehavior.AllowGet);

            return(clientsJson);
        }
예제 #4
0
        public virtual JsonResult ExportExcelMasterfile(List <ColumnModel> gridConfig, QueryInfo queryInfo)
        {
            var data     = new ExportExcel();
            var tempPath = Path.GetTempPath();
            var dataBind = MasterFileService.GetDataForGridMasterfile(queryInfo);

            string jsonTemp    = JsonConvert.SerializeObject(dataBind);
            var    dynamicTemp = JsonConvert.DeserializeObject <dynamic>(jsonTemp);
            string dataTemp    = JsonConvert.SerializeObject(dynamicTemp.Data);
            var    dataItem    = JsonConvert.DeserializeObject <List <dynamic> >(dataTemp);

            data.GridConfigViewModel = gridConfig;
            data.ListDataSource      = dataItem;

            using (var wb = new XLWorkbook())
            {
                string guid     = Guid.NewGuid().ToString();
                string filePath = Path.Combine(tempPath, guid + ".xlsx");
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }
                wb.Worksheets.Add(GenDataTableFromExportExcelType(data), typeof(TEntity).Name).ColumnsUsed().AdjustToContents();
                wb.SaveAs(filePath);
                return(Json(new { FileNameResult = guid + ".xlsx", Error = string.Empty }, JsonRequestBehavior.AllowGet));
            }

            //var content = RenderRazorViewToString("~/Views/Shared/Export/_BusinessReportExportContent.cshtml", data);
            //return Json(new { Item = content, Error = string.Empty }, JsonRequestBehavior.AllowGet);
        }
예제 #5
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);
        }
예제 #6
0
        public virtual IHttpActionResult DeleteMasterFile(TViewModel viewModel)
        {
            var entity = MasterFileService.GetById(viewModel.Id);

            //entity.LastModified = viewModel.LastModified;
            MasterFileService.Delete(entity);
            return(Ok(new { Error = string.Empty }));
        }
예제 #7
0
        public int Create(SystemConfigurationParameter parameters)
        {
            var viewModel   = MapFromClientParameters(parameters);
            var entity      = viewModel.MapTo <SystemConfiguration>();
            var savedEntity = MasterFileService.Add(entity);

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

            return(savedEntity.Id);
        }
예제 #9
0
        public virtual JsonResult DeleteMasterFile(TViewModel viewModel)
        {
            var entity = MasterFileService.GetById(viewModel.Id);

            entity.LastModified = viewModel.LastModified;
            MasterFileService.Delete(entity);

            return(Json(new { Error = string.Empty }, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
        public ActionResult Update(FranchiseeConfigurationParameter parameters)
        {
            using (var tran = new TransactionScope())
            {
                var viewModel = MapFromClientParameters(parameters);

                byte[] lastModified = null;

                var id           = 0;
                var name         = "";
                var logoFilePath = "";
                if (ModelState.IsValid)
                {
                    var sharViewModel = viewModel.SharedViewModel as DashboardFranchiseeConfigurationShareViewModel;


                    var entity       = MasterFileService.GetById(viewModel.SharedViewModel.Id);
                    var mappedEntity = viewModel.MapPropertiesToInstance(entity);
                    var mappedFranchiseeTernantDto = viewModel.MapTo <FranchiseeTernantDto>();

                    if (sharViewModel != null)
                    {
                        if (!String.IsNullOrEmpty(sharViewModel.Logo))
                        {
                            if (!sharViewModel.Logo.Contains("data:image/jpg;base64"))
                            {
                                logoFilePath      = Server.MapPath(sharViewModel.Logo);
                                mappedEntity.Logo = System.IO.File.ReadAllBytes(logoFilePath);
                                //_resizeImage.ResizeImageByHeight(logoFilePath, 40);
                            }
                        }
                    }
                    //gan value do bo bot filed trong _shared.cshtml
                    mappedEntity.FranchiseeContact = mappedEntity.Name;
                    mappedEntity.OfficePhone       = mappedEntity.PrimaryContactPhone;
                    mappedEntity.FaxNumber         = mappedEntity.PrimaryContactFax;

                    lastModified = MasterFileService.Update(mappedEntity).LastModified;
                    id           = mappedEntity.Id;
                    name         = mappedEntity.Name;

                    _webApiUserService.UpdateFranchiseeConfig(mappedFranchiseeTernantDto);
                    //Thread.Sleep(1000);
                }
                if (lastModified != null)
                {
                    if (!String.IsNullOrEmpty(logoFilePath) && System.IO.File.Exists(logoFilePath))
                    {
                        System.IO.File.Delete(logoFilePath);
                    }
                }
                tran.Complete();
                return(Json(new { Error = string.Empty, Data = new { id, name, LastModified = lastModified } },
                            JsonRequestBehavior.AllowGet));
            }
        }
예제 #11
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);
        }
예제 #12
0
        public JsonResult Delete(int id)
        {
            if (AuthenticationService.GetCurrentUser().User.Id == id)
            {
                var mess = string.Format(SystemMessageLookup.GetMessage("CannotDeleteYourself"));
                MasterFileService.ThrowCustomValidation(mess);
            }

            MasterFileService.DeleteById(id);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #13
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));
        }
예제 #14
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));
        }
예제 #15
0
        public ActionResult Update(SystemConfigurationParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);

            byte[] lastModified = null;

            if (ModelState.IsValid)
            {
                var entity       = MasterFileService.GetById(viewModel.SharedViewModel.Id);
                var mappedEntity = viewModel.MapPropertiesToInstance(entity);
                lastModified = MasterFileService.Update(mappedEntity).LastModified;
            }

            return(Json(new { Error = string.Empty, Data = new { LastModified = lastModified } }, JsonRequestBehavior.AllowGet));
        }
예제 #16
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));
        }
예제 #17
0
        public ActionResult Update(UserRoleParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);

            byte[] lastModified   = null;
            var    shareViewModel = viewModel.SharedViewModel as DashboardUserRoleShareViewModel;

            if (shareViewModel != null)
            {
                var entity = MasterFileService.GetById(shareViewModel.Id);
                //if (entity.AppRoleName == AppRole.GlobalAdmin.ToString())
                //{
                //    throw new Exception("Not allow to change global admin role function");
                //}
                var listRoleFunctionUpdate = shareViewModel.CheckAll ? GetAllRoleFunction() : ProcessMappingFromUserRoleGrid(shareViewModel.UserRoleFunctionData);
                var mappedEntity           = shareViewModel.MapPropertiesToInstance(entity);
                var listRoleFunctionOld    = mappedEntity.UserRoleFunctions;
                // 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);
                }
                // Add listUpdate
                mappedEntity.UserRoleFunctions.AddRange(listRoleFunctionUpdate);
                if (ModelState.IsValid)
                {
                    mappedEntity = MasterFileService.Update(mappedEntity);
                    lastModified = mappedEntity.LastModified;
                    MenuExtractData.Instance.RefershListData();
                }
            }


            return(Json(new { Error = string.Empty, Data = new { LastModified = lastModified } }, JsonRequestBehavior.AllowGet));
        }
예제 #18
0
        public virtual JsonResult UpdateMasterFile(MasterfileParameter parameters, Action <TViewModel> advanceMapping = null)
        {
            var viewModel = MapFromClientParameters(parameters);

            if (advanceMapping != null)
            {
                advanceMapping.Invoke(viewModel);
            }

            byte[] lastModified = null;

            if (ModelState.IsValid)
            {
                var entity       = MasterFileService.GetById(viewModel.SharedViewModel.Id);
                var mappedEntity = viewModel.MapPropertiesToInstance(entity);
                lastModified = MasterFileService.Update(mappedEntity).LastModified;
            }

            return(Json(new { Error = string.Empty, Data = new { LastModified = lastModified } }, JsonRequestBehavior.AllowGet));
        }
예제 #19
0
        public ActionResult Update(ScheduleParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);

            byte[] lastModified = null;

            if (ModelState.IsValid)
            {
                var entity = MasterFileService.GetById(viewModel.SharedViewModel.Id);

                var mappedEntity = viewModel.MapPropertiesToInstance(entity);
                lastModified = MasterFileService.Update(mappedEntity).LastModified;
                if (entity.WarningInfo != null && !entity.Confirm.GetValueOrDefault())
                {
                    return(Json(new { entity.Id, LastModified = lastModified, entity.WarningInfo, Error = "ErrorWarning" }, JsonRequestBehavior.DenyGet));
                }
                return(Json(new { entity.Id, LastModified = lastModified }, JsonRequestBehavior.DenyGet));
            }

            return(Json(new { Error = string.Empty, Data = new { LastModified = lastModified } }, JsonRequestBehavior.AllowGet));
        }
예제 #20
0
 public virtual IHttpActionResult DeleteMultiMasterfile(string selectedRowIdArray, string isDeleteAll)
 {
     if (isDeleteAll == "1")
     {
         MasterFileService.DeleteAll(o => o.Id > 0);
     }
     else
     {
         var liststrId = selectedRowIdArray.Split(',');
         var listId    = new List <long>();
         foreach (var item in liststrId)
         {
             long id;
             long.TryParse(item, out id);
             if (id != 0)
             {
                 listId.Add(id);
             }
         }
         MasterFileService.DeleteAll(o => listId.Contains(o.Id));
     }
     return(Ok(new { Error = string.Empty }));
 }
예제 #21
0
 public virtual JsonResult DeleteMultiMasterfile(string selectedRowIdArray, string isDeleteAll)
 {
     if (isDeleteAll == "1")
     {
         MasterFileService.DeleteAll(o => o.Id > 0);
     }
     else
     {
         var liststrId = selectedRowIdArray.Split(',');
         var listId    = new List <int>();
         foreach (var item in liststrId)
         {
             int id;
             int.TryParse(item, out id);
             if (id != 0)
             {
                 listId.Add(id);
             }
         }
         MasterFileService.DeleteAll(o => listId.Contains(o.Id));
     }
     return(Json(new { Error = string.Empty }, JsonRequestBehavior.AllowGet));
 }
예제 #22
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);
        }
예제 #23
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));
        }
예제 #24
0
        public virtual IHttpActionResult GetDataForGridMasterFile(QueryInfo queryInfo)
        {
            var queryData = MasterFileService.GetDataForGridMasterfile(queryInfo);

            return(Ok(queryData));
        }
예제 #25
0
 public ActionResult Delete(int id)
 {
     MasterFileService.DeleteById(id);
     MenuExtractData.Instance.RefershListData();
     return(Json(new { isSuccess = true }, JsonRequestBehavior.AllowGet));
 }
예제 #26
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));
        }
예제 #27
0
 public JsonResult Delete(int id)
 {
     MasterFileService.DeleteById(id);
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
예제 #28
0
        public JsonResult Update(RequestParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);

            byte[] lastModified = null;
            var    error        = "";
            var    newCourier   = ((DashboardRequestShareViewModel)viewModel.SharedViewModel).CourierId;
            var    entity       = MasterFileService.GetById(viewModel.SharedViewModel.Id);

            if (entity != null && entity.Status != (int)StatusRequest.NotSent)
            {
                error = string.Format(SystemMessageLookup.GetMessage("RequestCannotUpdate"), entity.Status.GetNameByValue <StatusRequest>());
            }
            else
            {
                if (entity.CourierId > 0 && newCourier != entity.CourierId)
                {
                    var courier = _userService.GetById(entity.CourierId.GetValueOrDefault());
                    if (courier.IsActive == false)
                    {
                        throw new Exception("Cannot assign request to inactive courier");
                    }
                }
                var mappedEntity = viewModel.MapPropertiesToInstance(entity);
                if (mappedEntity.IsStat == true)
                {
                    mappedEntity.Status      = (int)StatusRequest.Sent;
                    mappedEntity.SendingTime = DateTime.UtcNow;
                }
                else
                {
                    mappedEntity.Status = (int)StatusRequest.NotSent;
                }

                //Tinh estimate distance, estimate time
                var estimateDistance = 0;
                var estimateTime     = 0;
                if (entity != null && 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;
                        }
                    }
                }

                mappedEntity.EstimateDistance = estimateDistance;
                mappedEntity.EstimateTime     = estimateTime;

                lastModified = MasterFileService.Update(mappedEntity).LastModified;
            }
            return(Json(new { entity.WarningInfo, entity.Id, LastModified = lastModified, Error = error }, JsonRequestBehavior.DenyGet));
        }