Esempio n. 1
0
        public async Task <IActionResult> ModifyRight(int id, [FromBody] RightDTO project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest() as IActionResult);
            }

            var entity = await service.PutAsync(project);

            return(entity == null?StatusCode(304) as IActionResult
                   : Ok(entity));
        }
Esempio n. 2
0
        // POST: Rights
        public async Task <IActionResult> AddRight([FromBody] RightDTO project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest() as IActionResult);
            }

            var entity = await service.PostAsync(project);

            return(entity == null?StatusCode(409) as IActionResult
                   : Created($"{Request?.Scheme}://{Request?.Host}{Request?.Path}{entity.Id}",
                             entity));
        }
Esempio n. 3
0
        public ActionResult ChooseTrip(string trip_id)
        {
            int rightsId = this.rightsService.FindMaxId() + 1;
            int roleId   = this.rightsService.GetAllRoles().Where(e => e.Title == "Subscriber").Select(e => e.Role_ID).First();

            int      userId   = int.Parse(this.Session["User_ID"].ToString());
            int      tripId   = int.Parse(trip_id);
            RightDTO rightDTO = new RightDTO(rightsId, userId, roleId, tripId);

            try
            {
                this.rightsService.CreateRights(rightDTO);
                return(this.RedirectToAction("../Home/MyTrips"));
            }
            catch (ArgumentNullException ex)
            {
                this.ViewBag.ErrorMessage = "Ви вже обрали цю подорож.";
                return(this.RedirectToAction($"../TripDetail/TripDetail/{trip_id}"));
            }
        }
Esempio n. 4
0
        public void CreateRights(RightDTO rightsDto)
        {
            Right rights = new Right
            {
                Rights_ID = rightsDto.Rights_ID,
                Role_ID   = rightsDto.Role_ID,
                Trip_ID   = rightsDto.Trip_ID,
                User_ID   = rightsDto.User_ID,
            };

            try
            {
                this.Database.Rights.GetAll().Where(e => e.Role_ID == rights.Role_ID && e.Trip_ID == rights.Trip_ID && e.User_ID == rights.User_ID).First();
                throw new ArgumentNullException();
            }
            catch (System.InvalidOperationException)
            {
                this.Database.Rights.Create(rights);
                this.Database.Save();
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Insert([FromBody] RightDTO request)
        {
            try
            {
                if (this._rightService.Search(r => r.Name == request.Name).Any())
                {
                    return(BadRequest("Name must be unique"));
                }

                Right right = new Right()
                {
                    Name = request.Name
                };

                _rightService.Insert(right);
                return(Ok(right));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }