예제 #1
0
        public async Task <IActionResult> Edit(int id, ClientViewModel client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //client.ClientAppUserName = client.ClientName;
                    //var password = "******";
                    //client.ClientAppPassword = password;
                    _context.Update(client.GetModel());
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //if (User.IsInRole("Client"))
                //    return RedirectToAction(nameof(ClientView));
                return(RedirectToAction(nameof(Index)));
            }
            client.loadLists(_context);
            return(View(client));
        }
예제 #2
0
        public ActionResult Create(ClientViewModel model)
        {
            var svc      = new ClientAppService();
            var toCreate = model.GetModel();
            var result   = svc.Create(toCreate);

            if (result.Id > 0)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.ErrorMessage = "Erro ao criar o Cliente";
            return(View("New", model));
        }
예제 #3
0
        public async Task <IActionResult> Create(ClientViewModel client)
        {
            Random rd       = new Random();
            Int32  passCode = rd.Next(9999);

            if (ModelState.IsValid)
            {
                if (client.ClientCode == null)
                {
                    client.ClientCode = "C-" + passCode;
                }
                //client.ClientAppUserName = client.ClientName;
                client.ClientAppUserName = client.Email;
                var userName = client.ClientAppUserName;
                var email    = client.Email;
                var password = client.ClientName + passCode + "@Merkato";
                //var password = "******";
                client.ClientAppPassword = password;
                ApplicationRole applicationRole = await _roleManager.FindByNameAsync("Client");

                var role = applicationRole.Id;

                UserViewModel user = new UserViewModel();
                {
                    //user.UserName = userName;
                    user.Email             = email;
                    user.Password          = password;
                    user.ConfirmPassword   = password;
                    user.ApplicationRoleId = role;
                }

                Repository repository = new Repository(_userManager, _roleManager);

                await repository.CreateUser(user);

                _context.Add(client.GetModel());
                await _context.SaveChangesAsync();

                mailSender.SendEmail(client.Email, "Merkato Notification",
                                     $"{client.ClientName} Successffuly registered, kindly find your credentials below.{Environment.NewLine} -Username :{client.ClientAppUserName} {Environment.NewLine} -Password:{client.ClientAppPassword}"
                                     + $"{Environment.NewLine} -Client Code:{client.ClientCode}"
                                     + $"{Environment.NewLine} -Application link http://173.248.135.167/Merkato"
                                     + $"{Environment.NewLine}  {Environment.NewLine} {Environment.NewLine} Merkato Team", _context, false);


                return(RedirectToAction(nameof(Index)));
            }
            client.loadLists(_context);
            return(View(client));
        }