Exemple #1
0
        // [Authorize]
        public async Task <IActionResult> Post([FromBody] OrganizationCreateViewModel organization)
        {
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                // For testing purposes, uncomment the line below and comment the GetCurrentUserAsync() line.
                // ApplicationUser user = await context.ApplicationUser.SingleAsync(u => u.FirstName == "Matt");

                Organization org = new Organization()
                {
                    Organizer   = user,
                    Name        = organization.Name,
                    Description = organization.Description,
                    City        = organization.City,
                    State       = organization.State,
                    IsActive    = true
                };

                context.Add(org);

                await context.SaveChangesAsync();

                OrganizationViewModel model = new OrganizationViewModel(org, new ApplicationUserViewModel(user));
                return(Json(model));
            }
            return(BadRequest());
        }
Exemple #2
0
        public async Task <JsonResult> Create(OrganizationCreateViewModel model)
        {
            var organization = _mapper.Map <Organization>(model);

            if (_unitOfWork.Repository <Organization>().Exist(x => x.Name == model.Name))
            {
                return(Json(new { status = 207, message = _localizerService["AleadyTakenUsername"] }));
            }

            var result = await _unitOfWork.Repository <Organization>().AddAsync(organization);

            if (result.IsSuccess)
            {
                return(Json(new { status = 200, message = _localizerService["Success"] }));
            }

            return(Json(new { status = 406, message = _localizerService["Error"] }));
        }