Example #1
0
        public ActionResult Create(RegistrationCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                ReBindCreateModel(model);

                return(View(model));
            }

            try
            {
                CurrentUserId = UserService.GetByName(User.Identity.Name).SID;

                RegistrationService.Create(model.Note, CurrentUserId, model.TaskId, model.StartTime, model.EndTime, false);

                return(RedirectToAction("Index", "Registration"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                ModelState.AddModelError("", ex.StackTrace);
            }

            ReBindCreateModel(model);

            return(View(model));
        }
Example #2
0
        private void ReBindCreateModel(RegistrationCreateModel viewModel)
        {
            List <Customer> allCustomers            = CustomerService.All().ToList();
            List <Project>  projectsOfFirstCustomer = new List <Project>();

            if (allCustomers.Any())
            {
                if (viewModel.CustomerId != Guid.Empty)
                {
                    projectsOfFirstCustomer = ProjectService.All(viewModel.CustomerId).ToList();
                }
                else
                {
                    projectsOfFirstCustomer = ProjectService.All(allCustomers.First().Id).ToList();
                }
            }
            List <Task> tasksOfFirstProject = new List <Task>();

            if (projectsOfFirstCustomer.Any())
            {
                if (viewModel.ProjectId != Guid.Empty)
                {
                    tasksOfFirstProject = TaskService.All(viewModel.ProjectId).ToList();
                }
                else
                {
                    tasksOfFirstProject = TaskService.All(projectsOfFirstCustomer.First().Id).ToList();
                }
            }

            viewModel.Customers = new SelectList(allCustomers, "Id", "Name", viewModel.CustomerId);
            viewModel.Projects  = new SelectList(projectsOfFirstCustomer, "Id", "Name", viewModel.ProjectId);
            viewModel.Tasks     = new SelectList(tasksOfFirstProject, "Id", "Name", viewModel.TaskId);
        }
Example #3
0
        public ActionResult Create()
        {
            RegistrationCreateModel viewModel = new RegistrationCreateModel();

            ReBindCreateModel(viewModel);

            return(View(viewModel));
        }
Example #4
0
        public async Task <IActionResult> Create([FromBody] RegistrationCreateModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            await _userService.RegisterNewUser(model.UserName, model.Password, model.FirstName,
                                               model.LastName, model.Email, model.Gender, model.Latitude, model.Longitude);

            return(Created("/registration", new { Name = "test" }));
        }
        public Registration CreateRegistration(RegistrationCreateModel model)
        {
            Registration registration = new Registration
            {
                Username = model.Username,
                Password = model.Password,
                RoleId   = "2"
            };

            Create(registration);
            return(registration);
        }
Example #6
0
 public IActionResult Create([FromBody] RegistrationCreateModel model)
 {
     try
     {
         Registration registration = _uow.GetService <RegistrationDomain>().Create(model);
         if (registration != null)
         {
             _uow.SaveChanges();
             return(Success(registration.Username));
         }
         return(BadRequest());
     }
     catch (Exception ex)
     {
         return(Error(ex.Message));
     }
 }
Example #7
0
        public async Task <IActionResult> Post([FromBody] RegistrationCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userIdentity = new User()
            {
                UserName  = model.Username,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                IsBanned  = true,
            };
            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(Errors.AddErrorsToModelState(result, ModelState)));
            }
            await _userManager.AddToRoleAsync(userIdentity, model.RoleName);

            return(Ok("Account created"));
        }
 public Registration Create(RegistrationCreateModel model)
 {
     return(uow.GetService <IRegistrationRepository>().CreateRegistration(model));
 }