Пример #1
0
        public async Task Update(Client client, ClientUpdate update)
        {
            client.Name  = update.Name;
            client.Phone = update.Phone;
            client.Email = update.Phone;

            await repo.Update(client);
        }
Пример #2
0
        public async Task <bool> Update(int userId, ClientDto clientDto)
        {
            // TODO: [TESTS] (ClientService.Update) Add tests
            var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(Update))
                          .WithCategory(MetricCategory.Client, MetricSubCategory.Update)
                          .WithCustomInt1(userId)
                          .WithCustomInt2(clientDto.ClientId);

            try
            {
                using (builder.WithTiming())
                {
                    ClientEntity dbEntry;
                    using (builder.WithCustomTiming1())
                    {
                        builder.IncrementQueryCount();
                        dbEntry = await _clientRepo.GetById(clientDto.ClientId);

                        builder.CountResult(dbEntry);
                    }

                    if (dbEntry == null)
                    {
                        // TODO: [HANDLE] (ClientService.Update) Handle not found
                        return(false);
                    }

                    if (dbEntry.UserId != userId)
                    {
                        // TODO: [HANDLE] (ClientService.Update) Handle wrong owner
                        return(false);
                    }

                    using (builder.WithCustomTiming2())
                    {
                        builder.IncrementQueryCount();
                        if (await _clientRepo.Update(clientDto.ToDbEntity()) <= 0)
                        {
                            return(false);
                        }

                        builder.IncrementResultsCount();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogUnexpectedException(ex);
                builder.WithException(ex);
                return(false);
            }
            finally
            {
                await _metrics.SubmitPointAsync(builder.Build());
            }
        }
Пример #3
0
        public IActionResult Update(Client client)
        {
            if (!ModelState.IsValid)
            {
                return(View(client));
            }

            _clientRepo.Update(client);

            return(RedirectToAction("List"));
        }
Пример #4
0
        public IActionResult  Edit(EditClientViewModel _clientModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(_clientModel));
                }

                var client = _mapper.Map <Client>(_clientModel);

                _clientRepo.Update(client);
                return(Json(Ok()));
            }
            catch (Exception ex)
            {
                return(Json(BadRequest("Error updating" + ex)));
            }
        }
Пример #5
0
        public async Task <IActionResult> EditClient(Client client) // Edits Client Information and Updates User email/username as well
        {
            UserIdentity user = new UserIdentity();
            string       name = HttpContext.User.Identity.Name;

            user = await userManager.FindByNameAsync(name);

            Client c = clientRepo.GetClientByEmail(client.Email);

            if (c == null)
            {
                clientRepo.Create(client);
            }
            else
            {
                clientRepo.Update(client);
            }

            user.Email    = client.Email;
            user.UserName = client.Email;
            await userManager.UpdateAsync(user);

            await signInManager.SignOutAsync();

            Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync(user, user.Password, false, false);

            if (result.Succeeded)
            {
                if (await userManager.IsInRoleAsync(user, "Admin"))
                {
                    return(RedirectToAction("AdminPage", "Admin"));
                }
                else
                {
                    return(RedirectToAction("UserPage", "User"));
                }
            }

            return(RedirectToAction("UserPage", "User"));
        }
Пример #6
0
 public IActionResult UserEdit(Client client)
 {
     clientRepo.Update(client);
     return(RedirectToAction("ClientInfo", "Client"));
 }