public void TestCreate()
        {
            // Arrange
            var dish1 = new Dish
                        (
                "Brötchen",
                "Small bread",
                1.5M,
                Category.Starter,
                TimeOfDay.Weekends,
                true,
                1
                        );

            // Act
            var dish2 = crudService.Create(dish1);

            // Assert
            Assert.NotNull(dish2);
            Assert.IsType <Dish>(dish2);
            Assert.NotNull(dish2.Id);
            Assert.Equal(dish2.Name, dish1.Name);
            Assert.Equal(dish2.ShortDesc, dish1.ShortDesc);
            Assert.Equal(dish2.Category, dish1.Category);
            Assert.Equal(dish2.Availability, dish1.Availability);
            Assert.Equal(dish2.Price, dish1.Price);
            Assert.Equal(dish2.Active, dish1.Active);
            Assert.Equal(dish2.WaitingTime, dish1.WaitingTime);

            // For cleaning:
            fixture.DishesToDelete.Add(dish2);
        }
        public async Task <ActionResult> Registration(RegistrationViewModel model)
        {
            Task task = GetLanguages(model);

            if (ModelState.IsValid)
            {
                if (model.Password == model.ConfirmPassword)
                {
                    BaseResponseModelPost result = await _crudService.Create(model, null, UserService.UserEntity);

                    AddMessageToModel(model, result.Message, !result.Success);

                    if (result.Success)
                    {
                        AddViewModelToTempData(model);

                        return(RedirectToAction("Login"));
                    }
                }
                else
                {
                    AddMessageToModel(model, "Password and confirmed password are not equal!");
                }
            }

            await Task.WhenAll(task);

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([FromBody] PeopleMarkViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorMessage = string.Empty;

                foreach (var error in ModelState)
                {
                    foreach (var message in error.Value.Errors)
                    {
                        errorMessage += $"{message.ErrorMessage}\n";
                    }
                }

                return(StatusCode(500, ApiResult.FailResult(errorMessage)));
            }

            try
            {
                await _crudService.Create(model);
            }
            catch (DbUpdateException)
            {
                return(StatusCode(500,
                                  ApiResult.FailResult("Something went wrong while inserting data to database. Notice that \"Full Name\" should be unique.")));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ApiResult.FailResult(ex.Message)));
            }

            return(Ok(ApiResult.SuccessResult()));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            UserConferenceBinding existingBinding = _ucBindingService.GetAll().Result
                                                    .FindAll(binding => binding.UserId.Equals(UserId))
                                                    .Find(binding => binding.ConferenceId.Equals(ConferenceId));

            UserConferenceBinding newBinding = new UserConferenceBinding
            {
                UserId       = UserId,
                ConferenceId = ConferenceId,
                UserType     = UserType
            };

            if (existingBinding != null)
            {
                if (existingBinding.UserType != UserType)
                {
                    newBinding.UserConferenceBindingId = existingBinding.UserConferenceBindingId;
                    BindingCreated = await _ucBindingService.Update(newBinding);
                }
            }
            else
            {
                BindingCreated = await _ucBindingService.Create(newBinding);
            }

            Users = await _userService.GetAll();

            Conferences = await _conferenceService.GetAll();

            SelectListUsers       = new SelectList(Users, nameof(Models.User.UserId), nameof(Models.User.Email));
            SelectListConferences = new SelectList(Conferences, nameof(Conference.ConferenceId), nameof(Conference.Name));

            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(string imageName, int?id)
        {
            EventId = id;

            NewEvent.ConferenceId = 1;
            if (Duration != null)
            {
                NewEvent.Duration = TimeSpan.FromMinutes((int)Duration);
            }

            NewEvent.Image = imageName;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (EventId == null)
            {
                await _eventService.Create(NewEvent);
            }
            else
            {
                NewEvent.EventId = (int)EventId;
                await _eventService.Update(NewEvent);
            }

            return(RedirectToPage("/Events/EventIndex"));
        }
Beispiel #6
0
        //public async Task<IActionResult> OnGetAsync()
        //{

        //}

        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Speaker newSpeaker = new Speaker();

            newSpeaker.SpeakerId   = Id ?? 0;
            newSpeaker.FirstName   = speak.FirstName;
            newSpeaker.LastName    = speak.LastName;
            newSpeaker.Email       = speak.Email;
            newSpeaker.Image       = speak.Image;
            newSpeaker.Description = speak.Description;
            newSpeaker.Title       = speak.Title;

            if (IsNewEntry)
            {
                await SpeakerService.Create(newSpeaker);
            }
            else
            {
                await SpeakerService.Update(newSpeaker);
            }

            return(RedirectToPage("/Admin/Speaker/speakerCreate"));
        }
        public async Task <IActionResult> OnPostAsync(int?venueId, int?floorId)
        {
            if (floorId == 0)
            {
                Venues = await _venueService.GetAll();

                Floors = await _floorService.GetAll();

                Floors.Insert(0, new Floor());
                SelectListFloors = new SelectList(Floors.FindAll(floor => floor.VenueId.Equals(venueId) || floor.VenueId == 0), nameof(Floor.FloorId), nameof(Floor.Name));
                NewRoom.VenueId  = (int)venueId;
                VenueId          = (int)venueId;

                ModelState.Clear();
                return(Page());
            }

            NewRoom.VenueId = (int)venueId;
            NewRoom.FloorId = (int)floorId;

            if (!ModelState.IsValid)
            {
                return(RedirectToPage("Index"));
            }

            await _roomService.Create(NewRoom);

            return(RedirectToPage("Index"));
        }
        public async Task <IActionResult> CreateFlow([FromBody] CreateFlowRequest request)
        {
            try
            {
                var validator  = new CreateFlowRequestValidator();
                var validation = validator.Validate(request);
                if (!validation.IsValid)
                {
                    return(BadRequest(validation.Errors));
                }

                var flowModel = new FlowModel();
                flowModel.Name   = request.Name;
                flowModel.States = new List <FlowStateModel>();
                foreach (var state in request.States)
                {
                    flowModel.States.Add(new FlowStateModel
                    {
                        StateId = state.StateId,
                        Order   = state.Order
                    });
                }
                var id = await _flowService.Create(flowModel);

                return(Ok(id));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #9
0
        public IActionResult Create(MasterViewModel master)
        {
            if (ModelState.IsValid)
            {
                var createdMaster = new List <Master>();
                var error         = new List <Error>();

                try
                {
                    createdMaster.Add(_crudService.Create(master));
                    User user = new User {
                        Phone = master.Phone, Password = master.Password, FullName = master.FullName, RoleId = userId
                    };
                    _context.Users.Add(user);
                    _context.SaveChanges();
                }
                catch (ServiceOperationException exception)
                {
                    ViewBag.Error = ErrorFactory.IdentifyExceptionByType(exception).Description;
                    return(View(master));
                }

                return(RedirectToAction("Get", "MasterServices", new { masterId = master.Id }));
            }
            return(View(master));
        }
        public IActionResult Create([FromBody] JobSubmissionRequest model)
        {
            var user       = _userService.GetByUserName(User.FindFirstValue(ClaimTypes.Name));
            var submission = _mapper.Map <JobSubmission>(model);

            if (!_jobService.Exists(submission.JobId))
            {
                return(Ok(new BaseResponse("Job Not Found!")));
            }

            if (_jobSubmissionService.AlreadySubmitted(user.Client.Id, submission.JobId))
            {
                return(Ok(new BaseResponse("Already Submitted!")));
            }

            if (_jobSubmissionService.AlreadyAcceptedOtherSubmit(submission.JobId))
            {
                return(Ok(new BaseResponse("Already Accepted Other Submission!")));
            }

            submission.ClientId = user.Client.Id;
            var m = _crudService.Create(submission);

            return(Ok(new DataResponse <JobSubmissionResponse>(_mapper.Map <JobSubmissionResponse>(m))));
        }
        public async Task <IActionResult> OnPostAsync(int?eventId)
        {
            if (eventId == null)
            {
                return(BadRequest());
            }

            int?currentUserId = _sessionService.GetUserId(HttpContext.Session);

            if (currentUserId != null)
            {
                Enrollment enrollment = new Enrollment
                {
                    UserId     = currentUserId,
                    EventId    = eventId,
                    SignUpTime = DateTime.Now
                };

                SuccessfullySignedUp = await _enrollmentService.Create(enrollment);
            }

            await PageSetup((int)eventId);

            return(Page());
        }
Beispiel #12
0
 public ActionResult Create(TCreateInput input)
 {
     if (!ModelState.IsValid)
     {
         return(View(input));
     }
     return(Json(new { Id = s.Create(createMapper.MapToEntity(input, new TEntity())) }));
 }
 public virtual ActionResult Create(TCreateInput o)
 {
     if (!ModelState.IsValid)
     {
         return(View(v.RebuildInput(o)));
     }
     return(Json(new { Id = s.Create(v.BuildEntity(o)) }));
 }
Beispiel #14
0
 public ActionResult Create(TInput o)
 {
     if (!ModelState.IsValid)
     {
         return(View(v.RebuildInput(o)));
     }
     s.Create(v.BuildEntity(o));
     return(Content("ok"));
 }
        public async Task <IActionResult> OnPostSaveNewAsync(int?EId, int?UId)
        {
            // enrollment.User = UserSevice.GetFromId(enrollment.userId);
            //enrollment.Event = EventSevice.GetFromId(enrollment.eventId);

            await EnrollmentSevice.Create(enrollment);

            return(RedirectToPage("Enrollment"));
        }
Beispiel #16
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await featureService.Create(Feature);

            return(RedirectToPage("Index"));
        }
Beispiel #17
0
        public virtual ActionResult <www.OperationResult> Create([FromBody] WebModel input)
        {
            var id = _service.Create(_adapter.Adapt <DbModel>(input));

            return(Ok(new www.OperationResult
            {
                Message = $"{typeof(DbModel).Name} with the id of '{id}' was successfully created",
                Id = id,
            }));
        }
Beispiel #18
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _conferenceService.Create(Conference);

            return(RedirectToPage("ConferenceIndex"));
        }
Beispiel #19
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await floorService.Create(NewFloor);

            done = true;
            return(Page());
        }
Beispiel #20
0
        public async Task <IActionResult> ProjectAddPost(ProjectWorkModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _crudService.Create(model, Token, ProjectService.ProjectEntity);

                AddMessageToModel(model, result.Message, !result.Success);

                if (result.Success)
                {
                    return(RedirectToActionWithId(model, "ProjectEdit", "Project", result.Id));
                }
            }
            else
            {
                AddModelStateErrors(model);
            }

            return(View("Add", model));
        }
Beispiel #21
0
        public ActionResult Create(T entity)
        {
            var newEntity = _crudService.Create(entity);

            if (newEntity == null)
            {
                return(BadRequest());
            }

            return(Ok($"T {newEntity.ToString()} added successfully."));
        }
Beispiel #22
0
        public ActionResult Create(TCreateInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }
            var id = service.Create(createMapper.MapToEntity(input, new TEntity()));
            var e  = service.Get(id);

            return(Json(new { Content = this.RenderView(RowViewName, new[] { e }) }));
        }
Beispiel #23
0
        public IActionResult OnPostCreate(string imageName)
        {
            Room.VenueId = tempVenueId;
            Room.Image   = imageName;
            Room.Floor   = _floorService.GetFromId(Room.FloorId).Result.Name;
            Room.Events  = _eventService.GetAll().Result.FindAll(e => e.RoomId.Equals(Room.RoomId));
            foreach (int fId in SelectedFeatures)
            {
                Room.Features ??= new Dictionary <int, bool>();

                Feature f = _featureService.GetFromId(fId).Result;
                Room.Features.Add(f.FeatureId, true);
            }


            lock (_createRoomLock)
            {
                _roomService.Create(Room).Wait();

                if (Room.Features != null)
                {
                    if (Room.Features.Count != 0)
                    {
                        int maxId = 0;
                        maxId = _roomService.GetAll().Result.OrderByDescending(r => r.RoomId).First().RoomId;

                        foreach (int featureId in Room.Features.Keys)
                        {
                            RoomFeature rf = new RoomFeature
                            {
                                FeatureId = featureId, RoomId = maxId, IsAvailable = true
                            };

                            _roomFeatureService.Create(rf).Wait();
                        }
                    }
                }
            }

            return(RedirectToPage("/Admin/RoomTest/Index"));
        }
Beispiel #24
0
        public ActionResult Create(RoomDetailsVm model)
        {
            if (!ModelState.IsValid)
            {
                model.RoomTypes = new SelectList(_roomTypeCrudService.GetAll(), "Id", "Name");
                return(View("Details", model));
            }

            _roomCrudService.Create(_mapper.Map <RoomDetailsVm, RoomDto>(model));

            return(RedirectToAction("List"));
        }
Beispiel #25
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            User.PasswordRepeat = null;
            await _userService.Create(User);

            return(RedirectToPage("UserIndex"));
        }
        public ActionResult Create(CountryInput input)
        {
            if (ModelState.IsValid)
            {
                var country = mapper.Map <CountryInput, Country>(input);
                var id      = countryService.Create(country);
                country = countryService.Get(id);

                return(Json(new { Item = country }));
            }

            return(Json(ModelState.GetErrorsInline()));
        }
        public async Task <IActionResult> OnPostSaveNewAsync(int id)
        {
            Theme newTheme = new Theme();

            newTheme.ThemeId = id;
            newTheme.Name    = MyTheme.Name;

            ThemeService.Create(newTheme).Wait();

            Themes = await ThemeService.GetAll();

            return(Page());
        }
Beispiel #28
0
        public async Task <IActionResult> PostAsync([FromBody] ObjectModelPostDTO objectModelDto, string variableId)
        {
            var objectModel = new ObjectModel
            {
                VariableId     = variableId,
                VariableBool   = objectModelDto.VariableBool,
                VariableInt    = objectModelDto.VariableInt,
                VariableString = objectModelDto.VariableString
            };

            var objectService = await crudService.Create(objectModel);

            return(FromResult(objectService));
        }
Beispiel #29
0
        public virtual ActionResult Create(TViewModel viewModel)
        {
            //call service to create
            if (ModelState.IsValid)
            {
                var dto = Mapper.Map <TPoco>(viewModel);
                if (_service.Create(dto))
                {
                    viewModel = Mapper.Map <TViewModel>(dto);
                    return(RedirectToAction("Edit", new { id = viewModel.ID }));
                }
            }

            return(View(viewModel));
        }
Beispiel #30
0
        public async Task <IActionResult> CreateState([FromBody] CreateStateRequest request)
        {
            try
            {
                var stateModel = new StateModel();
                stateModel.Name = request.StateName;
                var id = await _stateService.Create(stateModel);

                return(Ok(id));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }