예제 #1
0
        public async Task <List <DeliveryModel> > ListForCourier()
        {
            int currentUserId = await currentUser.CurrentUserId();

            return(await context.Delivery
                   .Include(d => d.CourierService)
                   .Include(d => d.Courier)
                   .Where(d => d.Courier.Id == currentUserId)
                   .Select(d => d.ToDto())
                   .ToListAsync());
        }
예제 #2
0
        public async Task <IActionResult> Register([FromForm] CourierRegistrationModel model)
        {
            string logoUrl = null;

            if (model.Logo != null)
            {
                logoUrl = await fileService.Publish(model.Logo.OpenReadStream(),
                                                    Path.GetExtension(model.Logo.FileName));
            }

            var reguser = new ApplicationUser
            {
                Email          = model.Email,
                UserName       = model.Email,
                DisplayName    = model.DisplayName,
                LogoUrl        = logoUrl,
                PhoneNumber    = model.PhoneNumber,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = true
            };

            var result = await userManager.CreateAsync(reguser, model.Password);

            if (result.Succeeded != true)
            {
                return(BadRequest());
            }

            await userManager.AddToRoleAsync(reguser, Constatns.RoleNames.CURRIER);

            var currentUserId = await currentUser.CurrentUserId();

            context.CourierServiceToCourier.Add(new CourierServiceToCourier
            {
                Courier        = reguser,
                CourierService = await context.Users.FirstOrDefaultAsync(u => u.Id == currentUserId)
            });
            await context.SaveChangesAsync();

            return(Ok());
        }
예제 #3
0
        public async Task AddFirebaseToken(string token)
        {
            var prevToken = await dbContext.FcmToken.FirstOrDefaultAsync(t => t.Token == token);

            if (prevToken == null)
            {
                var t = new FcmToken
                {
                    UserId = await currentUserService.CurrentUserId(),
                    Token  = token
                };

                dbContext.FcmToken.Add(t);
            }

            await dbContext.SaveChangesAsync();
        }
예제 #4
0
        public async Task <IActionResult> UpdateSME([FromForm] EditProfileModel model)
        {
            string logoUrl = null;

            if (model.Logo != null)
            {
                logoUrl = await fileService.Publish(model.Logo.OpenReadStream(),
                                                    Path.GetExtension(model.Logo.FileName));
            }
            string flierUrl = null;

            if (model.Flier != null)
            {
                flierUrl = await fileService.Publish(model.Flier.OpenReadStream(),
                                                     Path.GetExtension(model.Flier.FileName));
            }

            var currentUser = await currentUserService.CurrentUserId();

            var sme = context.Users.FirstOrDefault(x => x.Id == currentUser);

            if (sme != null)
            {
                sme.Address     = model.Address;
                sme.City        = model.City;
                sme.DisplayName = model.DisplayName;
                sme.ContactName = model.ContactName;
                sme.ZipCode     = model.ZipCode;
                sme.PhoneNumber = model.PhoneNumber;
                sme.LogoUrl     = logoUrl ?? sme.LogoUrl;
                sme.FlierUrl    = flierUrl ?? sme.FlierUrl;
            }

            await context.SaveChangesAsync();

            return(Ok());
        }