コード例 #1
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));
        }
コード例 #2
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));
            }
        }
コード例 #3
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));
        }
コード例 #4
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));
        }
コード例 #5
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));
        }
コード例 #6
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));
        }
コード例 #7
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));
        }