Esempio n. 1
0
        public ResponseModel EditClient(EditClientModel model)
        {
            var resp = new ResponseModel();

            try
            {
                ValidationResult validateClient = new EditClientModelValidator().Validate(model);
                if (validateClient.IsValid)
                {
                    Client client = _clientRepository.GetClientByUserId(Guid.Parse(model.UserId));
                    if (client != null)
                    {
                        EditUserModel editUserModel = new EditUserModel
                        {
                            UsuarioId    = model.UserId,
                            Name         = model.Name,
                            Locations    = model.Locations,
                            PhoneNumbers = model.PhoneNumbers,
                            Imagem       = model.Imagem
                        };

                        ResponseModel userResponse = _userService.EditUserFromModel(editUserModel);
                        if (userResponse.Success)
                        {
                            User clientUser = userResponse.Result as User;

                            client.RG            = model.RG;
                            client.LastUpdatedAt = DateTimeUtil.UtcToBrasilia();
                            client.UpdatedBy     = clientUser.UserId;
                            client.User          = clientUser;
                            _clientRepository.Edit(client);

                            resp.Success = true;
                            resp.Message = "Cliente editado com sucesso";
                        }
                        else
                        {
                            resp = userResponse;
                        }
                    }
                    else
                    {
                        resp.Message = "Cliente não encontrado";
                    }
                }
                else
                {
                    resp.Message = validateClient.Errors.FirstOrDefault().ErrorMessage;
                }
            }
            catch (Exception e)
            {
                resp.Message = "Não foi possível editar o cliente";
            }

            return(resp);
        }
Esempio n. 2
0
        public ActionResult EditClient([FromForm] EditClientModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                ResponseModel result = _clientService.EditClient(model);
                return(Ok(result));
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
Esempio n. 3
0
        public ActionResult EditClient(EditClientModel model)
        {
            if (ModelState.IsValid)
            {
                Client editableClient = CurrentClient();//context.ClientSet.FirstOrDefault(x => x.Id == model.Id);
                if (editableClient != null)
                {
                    editableClient.FirstName  = model.FirstName;
                    editableClient.LastName   = model.LastName;
                    editableClient.MiddleName = model.MiddleName;
                    editableClient.Adress     = model.Adress;
                    editableClient.BirthDay   = model.BirthDay;
                    context.SaveChanges();
                    ViewBag.RegisterSucess = "Изменения внесены успешно";
                    return(View());
                }
            }

            return(HttpNotFound());
        }
Esempio n. 4
0
        public IActionResult EditClient(EditClientModel model, [FromServices] ConfigurationDbContext configContext)
        {
            // Validate it's an actual client
            var foundClient = configContext.Clients.Where(c => c.ClientId == model.ClientId).FirstOrDefault();

            if (foundClient != null)
            {
                foundClient.ClientName = model.Name;
                foundClient.ClientUri  = model.HomepageUrl;
                foundClient.LogoUri    = model.LogoUrl;
                foundClient.Updated    = DateTime.Now;
                configContext.Entry(foundClient).State = EntityState.Modified;

                // Update the redirect URL for this client
                var results = configContext.Set <ClientRedirectUri>().Where(c => c.ClientId == foundClient.Id).ToList();
                if (results != null)
                {
                    configContext.RemoveRange(results);
                }
                var newUri = new ClientRedirectUri();
                newUri.Client      = foundClient;
                newUri.ClientId    = foundClient.Id;
                newUri.RedirectUri = model.CallbackUrl;
                configContext.Add(newUri);

                // Generate the origin for the callback
                Uri    redirect = new Uri(model.CallbackUrl);
                string origin   = redirect.Scheme + "://" + redirect.Host;

                // Update the allowed origin for this client
                var corsOrigins = configContext.Set <ClientCorsOrigin>().Where(c => c.ClientId == foundClient.Id).ToList();
                if (corsOrigins != null)
                {
                    configContext.RemoveRange(corsOrigins);
                }
                var newOrigin = new ClientCorsOrigin();
                newOrigin.Client   = foundClient;
                newOrigin.ClientId = foundClient.Id;
                newOrigin.Origin   = origin;
                configContext.Add(newUri);

                // Update their allowed grants
                var curGrants = configContext.Set <ClientGrantType>().Where(c => c.ClientId == foundClient.Id).ToList();
                if (curGrants != null)
                {
                    configContext.RemoveRange(curGrants);
                }
                foreach (var grantType in model.AllowedGrants)
                {
                    var newGrant = new ClientGrantType();
                    newGrant.Client    = foundClient;
                    newGrant.ClientId  = foundClient.Id;
                    newGrant.GrantType = grantType;
                    configContext.Add(newGrant);
                }

                // Update their allowed scopes
                var curScopes = configContext.Set <ClientScope>().Where(c => c.ClientId == foundClient.Id).ToList();
                if (curScopes != null)
                {
                    configContext.RemoveRange(curScopes);
                }
                foreach (var scope in model.AllowedScopes)
                {
                    var newScope = new ClientScope();
                    newScope.Client   = foundClient;
                    newScope.ClientId = foundClient.Id;
                    newScope.Scope    = scope;
                    configContext.Add(newScope);
                }

                // Save all the changed
                configContext.SaveChanges();

                // Clear the client cache
                RemoveCachedClient(model.ClientId);

                return(new JsonResult(new { success = true }));
            }

            return(new JsonResult(new { success = false, message = "Client does not exist." }));
        }