public async Task <bool> SaveComponentAsync(UserComponentType type)
        {
            try
            {
                await _context.AddAsync(type);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <bool> SaveDetailsAsync(IEnumerable <UserComponentTypeDetail> details)
        {
            if (details == null)
            {
                return(false);
            }

            try
            {
                await _context.UserComponentTypeDetails.AddRangeAsync(details);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <bool> SaveChangesAsync(StaticSiteInfo info)
        {
            try
            {
                _context.Update(info);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #4
0
        public async Task <bool> ResetPrimaryStatuses(ComponentTypeDetail detail)
        {
            if (detail == null || detail.Id == 0)
            {
                return(false);
            }

            var details = _context.ComponentTypeDetails
                          .Where(x => x.ComponentTypeId == detail.ComponentTypeId && x.Id != detail.Id);

            await details.ForEachAsync(x => x.IsPrimary = false);

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            if (Input.FormFile == null)
            {
                return(RedirectToPage());
            }

            var imageId = await _cloudinaryService.UploadImageAsync(Input.FormFile);

            if (string.IsNullOrWhiteSpace(imageId))
            {
                return(RedirectToPage());
            }

            // Deleting old profile image if any
            if (!string.IsNullOrWhiteSpace(user.ImageId))
            {
                await _cloudinaryService.DeleteImageAsync(user.ImageId);
            }

            // Setting the new profile image
            user.ImageId = imageId;

            _dbContext.Update(user);
            await _dbContext.SaveChangesAsync();

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Your profile has been updated";
            return(RedirectToPage());
        }
        public async Task <bool> SaveChangesAsync(UnitMultiplier multiplier)
        {
            try
            {
                if (multiplier.Id == 0)
                {
                    await _context.AddAsync(multiplier);
                }
                else
                {
                    _context.Update(multiplier);
                }

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #7
0
        public async Task <bool> SaveChangesAsync(ComponentType type)
        {
            try
            {
                if (type.Id == 0)
                {
                    await _context.AddAsync(type);
                }
                else
                {
                    _context.Update(type);
                }

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }