コード例 #1
0
        public AppActionResult Run(CurrentUserDto user, Order order)
        {
            order.Status         = OrderState.Created;
            order.ShippingStatus = VehicleState.VehicleEmpty;
            order.DeliveryStatus = VehicleState.VehicleEmpty;

            var shipping = _dataService.GetById <Shipping>(order.ShippingId.Value);

            order.ShippingId          = null;
            order.ShippingNumber      = null;
            order.OrderShippingStatus = null;

            _historyService.Save(order.Id, "orderRemovedFromShipping", order.OrderNumber, shipping.ShippingNumber);

            var orders = _dataService.GetDbSet <Order>().Where(x => x.ShippingId == shipping.Id && x.Id != order.Id)
                         .ToList();

            _historyService.Save(shipping.Id, "orderRemovedFromShipping", order.OrderNumber, shipping.ShippingNumber);

            _shippingCalculationService.RecalculateShipping(shipping, orders);

            _shippingGetRouteService.UpdateRoute(shipping, orders);

            var changes       = _dataService.GetChanges <Shipping>().FirstOrDefault(x => x.Entity.Id == shipping.Id);
            var changeTracker = _changeTrackerFactory.CreateChangeTracker().TrackAll <Shipping>();

            changeTracker.LogTrackedChanges(changes);

            return(new AppActionResult
            {
                IsError = false,
                Message = "orderRemovedFromShipping".Translate(user.Language, order.OrderNumber,
                                                               shipping.ShippingNumber)
            });
        }
コード例 #2
0
        /// <summary>
        /// 获取当前用户菜单树
        /// </summary>
        /// <returns>用户菜单列表</returns>
        public ResponseBase <List <SysMenuDto> > GetCurrentUserMenu(CurrentUserDto currentUserDto)
        {
            var response = new ResponseBase <List <SysMenuDto> >();
            var model    = new List <SysMenuDto>();

            try
            {
                model = CacheManager.Get(currentUserDto.UserID.ToString() + CacheKeyConstantVariable.CurrentUserMenu, () =>
                {
                    if (null != currentUserDto.MenuIds)
                    {
                        model = SystemRepo.GetUserMenuByIdList(currentUserDto.MenuIds);
                    }
                    return(model);
                }, TimeSpan.FromDays(1));
                response.Result    = model;
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                response.IsSuccess     = false;
                response.OperationDesc = ex.ToString();
                WriteLogException(ex);
            }
            return(response);
        }
コード例 #3
0
        /// <summary>
        /// 创建步骤操作信息
        /// </summary>
        public async Task CreateStepsAsync(TaskTemplateStepDto stepDto, CurrentUserDto user)
        {
            var template = await _context.TaskTemplates.FirstOrDefaultAsync(x => x.Id == stepDto.TemplateId);

            template.SetStep(TaskTemplateStep.DesignSteps);
            //删除以前的数据
            var operates = await _context.TaskTemplateStepOperates.Where(x => x.StepId == stepDto.Id).ToListAsync();

            if (operates.AnyOne())
            {
                _context.TaskTemplateStepOperates.RemoveRange(operates);
            }
            var oldStep = await _context.TaskTemplateSteps.FirstOrDefaultAsync(x => x.Id == stepDto.Id);

            if (oldStep != null)
            {
                _context.TaskTemplateSteps.Remove(oldStep);
            }
            var step = _mapper.Map <TaskTemplateStepEntity>(stepDto);

            step.Operates = step.Operates.Where(o => o.Name.IsNotBlank()).ToList();
            step.CreateEntity(user.UserId);
            step.Operates.ForEach(m =>
            {
                m.StepId = step.Id;
                m.CreateEntity(user.UserId);
            });
            await _context.TaskTemplateSteps.AddAsync(step);

            await _context.SaveChangesAsync();
        }
コード例 #4
0
        public AppActionResult Run(CurrentUserDto user, Shipping shipping)
        {
            var orders = _dataService.GetDbSet <Order>()
                         .Where(x => x.ShippingId.HasValue && x.ShippingId.Value == shipping.Id).ToList();
            var ordersIds = _dataService.GetDbSet <Order>()
                            .Where(x => x.ShippingId.HasValue && x.ShippingId.Value == shipping.Id)
                            .Select(_ => _.Id).ToArray();
            var itemsDbSet = _dataService.GetDbSet <OrderItem>();

            itemsDbSet.RemoveRange(itemsDbSet.Where(x => ordersIds.Contains(x.OrderId)));

            var historyDbSet = _dataService.GetDbSet <HistoryEntry>();

            historyDbSet.RemoveRange(historyDbSet.Where(x => ordersIds.Contains(x.PersistableId)));

            _dataService.GetDbSet <Order>().RemoveRange(orders);

            _dataService.GetDbSet <Shipping>().Remove(shipping);
            historyDbSet.RemoveRange(historyDbSet.Where(x => x.PersistableId == shipping.Id));

            _historyService.Save(shipping.Id, "deleteShipping", shipping.ShippingNumber);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingDeleted".Translate(user.Language, shipping.ShippingNumber)
            });
        }
コード例 #5
0
        /// <summary>
        /// 创建任务流模板
        /// </summary>
        public async Task <string> CreateAsync(TaskTemplateDto templateDto, CurrentUserDto user)
        {
            if (templateDto.Name.IsBlank())
            {
                throw new Exception("模板名称不能为空");
            }
            if (templateDto.Id.IsNotBlank())
            {
                var template = await _context.TaskTemplates.FindAsync(templateDto.Id);

                if (template != null)
                {
                    template.Name = templateDto.Name;
                }
            }
            else
            {
                var template = new TaskTemplateEntity {
                    Name = templateDto.Name
                };
                template.CreateEntity(user.UserId);
                template.SetStep(TaskTemplateStep.Save);
                await _context.AddAsync(template);

                templateDto.Id = template.Id;
            }

            await _context.SaveChangesAsync();

            return(templateDto.Id);
        }
コード例 #6
0
        public IActionResult CurrentUser()
        {
            CurrentUserDto result = new CurrentUserDto();

            try
            {
                var user = GetCurrentUser();
                if (user == null)
                {
                    throw new Exception("User not found");
                }

                var userEasyName = GetUserClaim("UserName", user).Value;
                Logger.LogInformation($"userEasyName: {userEasyName}");

                result = new CurrentUserDto
                {
                    Name      = userEasyName,
                    Role      = GetUserClaim(ClaimTypes.Role, user)?.Value.ToUpper(),
                    Id        = user.Id,
                    FirstName = userEasyName,
                    LastName  = null
                };
            }
            catch (Exception ex)
            {
                Logger.LogDebug($"{ex.Message} : {ex.InnerException}");
                throw ex;
            }

            return(Ok(GetJsonFromObject(result)));
        }
コード例 #7
0
        public async Task Logout()
        {
            await api.Logout();

            _currentUser = null;
            NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
        }
コード例 #8
0
        public async Task <ActionResult <CurrentUserDto> > Login(LoginDto dto)
        {
            var user = await userManager.FindByNameAsync(dto.Username);

            if (user == null)
            {
                return(BadRequest(new SignInResult()));
            }
            var result = await signInManager.CheckPasswordSignInAsync(user, dto.Password, true);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }
            await signInManager.SignInAsync(user, false, "Password");

            var roles = await userManager.GetRolesAsync(user);

            var currentUserDTO = new CurrentUserDto
            {
                Name     = user.Name,
                Username = user.UserName,
                Email    = user.Email,
                Roles    = roles,
            };

            return(Ok(currentUserDTO));
        }
コード例 #9
0
ファイル: UserInfoService.cs プロジェクト: BogTodES/BlogAppV1
 public UserInfoService(UnitOfWork unit, CurrentUserDto currentUserDto,
                        BlockService blockService, FriendsService friendsService) :
     base(unit, currentUserDto)
 {
     this.blockService   = blockService;
     this.friendsService = friendsService;
 }
コード例 #10
0
        public static async Task Logout()
        {
            var accounts = await FindAccountsForServiceAsync();

            accounts.RemoveAll(a => a.Username == User.Username);
            User = null;
            SystemApi.Logout();
            CrossFirebasePushNotification.Current.UnsubscribeAll();
        }
コード例 #11
0
        private async Task <CurrentUserDto> GetCurrentUser()
        {
            if (_currentUser != null && _currentUser.IsAuthenticated)
            {
                return(_currentUser);
            }
            _currentUser = await api.CurrentUserInfo();

            return(_currentUser);
        }
コード例 #12
0
        public static async Task <bool> AutoLogin()
        {
            var user = await GetUser();

            if (user == null || user.TokenExpirationDate < DateTime.Now)
            {
                return(false);
            }
            User = user;
            SystemApi.AuthApi(user.Token);
            return(true);
        }
コード例 #13
0
        public AppActionResult Run(CurrentUserDto user, Order order)
        {
            order.Status = OrderState.FullReturn;

            _historyService.Save(order.Id, "orderSetFullReturn", order.OrderNumber);

            return(new AppActionResult
            {
                IsError = false,
                Message = "orderSetFullReturn".Translate(user.Language, order.OrderNumber)
            });
        }
コード例 #14
0
        public bool ValidateToken(string token)
        {
            try
            {
                CurrentUser = JWT.Decode <CurrentUserDto>(token, Encoding.UTF8.GetBytes(_jwtKey));
            }
            catch
            {
                return(false);
            }

            return(CurrentUser != null);
        }
コード例 #15
0
        public async Task LoadCurrentUserAsync(string email)
        {
            var user = await DbContext.Users.AsNoTracking().FirstOrDefaultAsync(u => u.Email == email);

            if (user != null)
            {
                CurrentUser = new CurrentUserDto {
                    Email = user.Email, Id = user.Id, Name = user.UserName
                }
            }
            ;
        }
    }
コード例 #16
0
        public async Task <IActionResult> CreateMembership(CurrentUserDto currentUserDto)
        {
            User user = await repo.CreateMembership(currentUserDto);

            await userManager.AddToRoleAsync(user, "Member");

            if (await repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating user {user.Id} failed on save");
        }
コード例 #17
0
ファイル: UsersController.cs プロジェクト: nesfit/Coffee
        public async Task <ActionResult> UpdateCurrentUser(CurrentUserDto userDto)
        {
            var userId = User.GetUserId();
            var user   = await _usersService.GetUser(userId);

            if (user is null)
            {
                return(NotFound());
            }

            var command = new UpdateUser(userId, userDto.FullName, userDto.EmailAddress, user.IsAdministrator, user.IsActive);

            return(await SendAndHandleOperationCommand(command));
        }
コード例 #18
0
 public static void Connected(string connectionId, CurrentUserDto user, string userIdentifier)
 {
     if (!string.IsNullOrEmpty(connectionId))
     {
         if (ConnectedIds.ContainsKey(user.Id.ToString()))
         {
             ConnectedIds.TryRemove(user.Id.ToString(), out var userOut);
         }
         ConnectedIds.AddOrUpdate(user.Id.ToString(), (a) =>
         {
             return(new MemberInfo(userIdentifier, connectionId, user));
         }, (s, info) => info);
     }
 }
コード例 #19
0
        public AppActionResult Run(CurrentUserDto user, Order order)
        {
            if (order?.ShippingId == null)
            {
                return(new AppActionResult
                {
                    IsError = true,
                    Message = "orderShippingNotFound".Translate(user.Language)
                });
            }

            var shipping = _dataService.GetById <Shipping>(order.ShippingId.Value);

            return(_shippingAction.Run(user, shipping));
        }
コード例 #20
0
        public CurrentUserDto GetCurrentUser()
        {
            User user = db.Users.GetById(EnsureCurrentUserId());

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            CurrentUserDto dto = mapper.Map <CurrentUserDto>(user);

            dto.RoleType = db.Roles.GetById(user.RoleId).RoleType;
            dto.Language = GetCurrentUserLanguage();

            return(dto);
        }
コード例 #21
0
        public async Task <ActionResult <CurrentUserDto> > GetRole()
        {
            var user = await userManager.GetUserAsync(HttpContext.User);

            var roles = await userManager.GetRolesAsync(user);

            var currentUserDTO = new CurrentUserDto
            {
                Name     = user.Name,
                Username = user.UserName,
                Email    = user.Email,
                Roles    = roles,
            };

            return(Ok(currentUserDTO));
        }
コード例 #22
0
        public AppActionResult Run(CurrentUserDto user, Shipping shipping)
        {
            shipping.Status = ShippingState.ShippingArhive;

            foreach (var order in _dataService.GetDbSet <Order>().Where(o => o.ShippingId == shipping.Id))
            {
                order.OrderShippingStatus = shipping.Status;
            }

            _historyService.Save(shipping.Id, "shippingSetArchived", shipping.ShippingNumber);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetArchived".Translate(user.Language, shipping.ShippingNumber)
            });
        }
コード例 #23
0
        public static UserUpdateDto ToUserUpdateDto(UserUpdateRequest request, CurrentUserDto currentUser)
        {
            var dto = new UserUpdateDto
            {
                Id       = request.Id,
                Account  = request.Account.Trim(),
                Name     = request.Name.Trim(),
                Deptid   = request.Deptid,
                Birthday = request.Birthday,
                Email    = request.Email,
                Phone    = request.Phone,
                Sex      = request.Sex,
                Status   = request.Status ? AccountStatus.Active : AccountStatus.InActive,
                ModifyBy = currentUser.Id
            };

            return(dto);
        }
コード例 #24
0
        private void SaveInner(CurrentUserDto user, Guid entityId, string messageKey, params object[] messageArgs)
        {
            string userName = GetUserName(user);

            string[]     valueArgs = messageArgs.Select(GetDisplayValue).ToArray();
            string       strArgs   = JsonConvert.SerializeObject(valueArgs);
            HistoryEntry entry     = new HistoryEntry
            {
                PersistableId = entityId,
                UserId        = user?.Id,
                UserName      = userName,
                CreatedAt     = DateTime.UtcNow,
                MessageKey    = messageKey,
                MessageArgs   = strArgs
            };

            _dataService.GetDbSet <HistoryEntry>().Add(entry);
        }
コード例 #25
0
        public AppActionResult Run(CurrentUserDto user, Shipping shipping)
        {
            var newState = new ShippingState?();

            if (shipping.Status == ShippingState.ShippingCompleted)
            {
                newState = ShippingState.ShippingConfirmed;
            }

            if (shipping.Status == ShippingState.ShippingBillSend)
            {
                newState = ShippingState.ShippingCompleted;
            }

            if (shipping.Status == ShippingState.ShippingArhive)
            {
                newState = ShippingState.ShippingBillSend;
            }


            if (newState.HasValue)
            {
                shipping.Status = newState.Value;

                foreach (var order in _dataService.GetDbSet <Order>().Where(o => o.ShippingId == shipping.Id))
                {
                    order.OrderShippingStatus = shipping.Status;
                }

                _historyService.Save(shipping.Id, "shippingRollback",
                                     shipping.ShippingNumber,
                                     newState.ToString().ToLowerFirstLetter());
            }

            string newStateName = newState?.ToString()?.ToLowerFirstLetter().Translate(user.Language);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingRollback".Translate(user.Language,
                                                       shipping.ShippingNumber,
                                                       newStateName)
            });
        }
コード例 #26
0
 private string GetUserName(CurrentUserDto user)
 {
     if (user == null)
     {
         return("System");
     }
     else
     {
         Role role = user.RoleId.HasValue ? _dataService.GetById <Role>(user.RoleId.Value) : null;
         if (role == null)
         {
             return(user.Name);
         }
         else
         {
             return($"{user.Name} ({role.Name})");
         }
     }
 }
コード例 #27
0
        public IActionResult CurrentUser()
        {
            CurrentUserDto result;

            try
            {
                var headerValue = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer", string.Empty).Trim();
                var handler     = new JwtSecurityTokenHandler();
                var jwtUser     = handler.ReadJwtToken(headerValue);

                if (jwtUser != null)
                {
                    var userId = jwtUser.Claims.FirstOrDefault(c => c.Type == "ID").Value;

                    var user         = _userManager.Users.FirstOrDefault(u => u.Id == userId);
                    var userEasyName = user.UserName;
                    _logger.LogInformation($"userEasyName: {userEasyName}");

                    result = new CurrentUserDto
                    {
                        Name      = userEasyName,
                        Role      = userEasyName.ToLower().Contains("waiter") ? "WAITER" : "CUSTOMER",
                        Id        = null,
                        FirstName = user.UserName,
                        LastName  = null
                    };
                }
                else
                {
                    result = new CurrentUserDto();
                }
            }
            catch (Exception ex)
            {
                _logger.LogDebug($"{ex.Message} : {ex.InnerException}");
                result = new CurrentUserDto();
            }

            var json = JsonConvert.SerializeObject(result, _serializerSettings);

            return(Ok(json));
        }
コード例 #28
0
        public AppActionResult Run(CurrentUserDto user, Shipping shipping)
        {
            shipping.Status = ShippingState.ShippingConfirmed;

            var orders = _dataService.GetDbSet <Order>().Where(x => x.ShippingId.HasValue && x.ShippingId.Value == shipping.Id).ToList();

            foreach (Order order in orders)
            {
                order.ShippingStatus      = VehicleState.VehicleWaiting;
                order.OrderShippingStatus = shipping.Status;
            }

            _historyService.Save(shipping.Id, "shippingSetConfirmed", shipping.ShippingNumber);

            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetConfirmed".Translate(user.Language, shipping.ShippingNumber)
            });
        }
コード例 #29
0
        public AppActionResult Run(CurrentUserDto user, Shipping shipping)
        {
            if (shipping.CarrierId == null)
            {
                return new AppActionResult
                       {
                           IsError = true,
                           Message = "shippingDontSetRequestSentDontSetTk".Translate(user.Language, shipping.ShippingNumber)
                       }
            }
            ;

            var transportCompany = _dataService.GetById <TransportCompany>(shipping.CarrierId.Value);
            var currentUser      = _dataService.GetById <User>(user.Id.Value);

            if (transportCompany.Title == "FM Logistic" && currentUser.IsFMCPIntegrated())
            {
                using (var fmcp = new FMCPIntegration(currentUser, _dataService))
                {
                    var fmcpWaybillId = fmcp.CreateWaybill(shipping);
                    _historyService.Save(shipping.Id, "shippingSetRequestSent", shipping.ShippingNumber);
                    shipping.FmcpWaybillId = fmcpWaybillId;
                }
            }

            shipping.Status = ShippingState.ShippingRequestSent;

            foreach (var order in _dataService.GetDbSet <Order>().Where(o => o.ShippingId == shipping.Id))
            {
                order.OrderShippingStatus = shipping.Status;
            }

            _historyService.Save(shipping.Id, "shippingSetRequestSent", shipping.ShippingNumber);


            return(new AppActionResult
            {
                IsError = false,
                Message = "shippingSetRequestSent".Translate(user.Language, shipping.ShippingNumber)
            });
        }
コード例 #30
0
        public static async Task <CurrentUserDto> GetUser()
        {
            var account = await FindAccountForServiceAsync();

            if (account == null)
            {
                return(null);
            }
            var user = new CurrentUserDto()
            {
                Id                  = int.Parse(account.Properties["Id"]),
                FirstName           = account.Properties["FirstName"],
                LastName            = account.Properties["LastName"],
                Username            = account.Properties["Username"],
                UserRole            = Enum.Parse <UserRole>(account.Properties["UserRole"]),
                Token               = account.Properties["Token"],
                TokenExpirationDate = DateTime.Parse(account.Properties["TokenExpirationDate"])
            };

            return(user);
        }