public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <CategoryLocalTravel>();

            try
            {
                var entity = await _repository.Query().Include(x => x.City).FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                response.Model = entity;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <FunctionResource>();

            try
            {
                var entity = await GetFunctionWithRelated(id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }
                var resource = new FunctionResource();
                _mapper.Map(entity, resource);
                response.Model = resource;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Create(SaveFunctionResource resource)
        {
            var response = new SingleModelResponse <FunctionResource>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = "Input cannot be null.";
                return(response.ToHttpResponse());
            }

            try
            {
                var function = new Function();
                _mapper.Map(resource, function);

                var entity = await _functionRepository.AddAsync(function);

                var entityMap = await GetFunctionWithRelated(entity.Id);

                response.Model   = _mapper.Map <Function, FunctionResource>(entityMap);
                response.Message = "The data was saved successfully.";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Update(int id, SaveFunctionResource resource)
        {
            var response = new SingleModelResponse <FunctionResource>();

            try
            {
                var entity = await GetFunctionWithRelated(id);

                if (entity == null || resource == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                _mapper.Map(resource, entity);

                await _functionRepository.UpdateAsync(entity);

                var entityMap = await GetFunctionWithRelated(entity.Id);

                response.Model   = _mapper.Map <Function, FunctionResource>(entityMap);
                response.Message = "The data was saved successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <FunctionResource>();

            try
            {
                var entity = await GetFunctionWithRelated(id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                await _roleFunctionService.Delete(entity.RoleFunctions.ToList());

                await _functionRepository.DeleteAsync(entity.Id);

                response.Model   = _mapper.Map <Function, FunctionResource>(entity);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
示例#6
0
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <UserGridResource>();

            try
            {
                var entity = await _userRepository.FindAsync(x => x.Id == id && x.IsActive);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                entity.IsActive = false;

                await _userRepository.UpdateAsync(entity);

                response.Model   = _mapper.Map <User, UserGridResource>(entity);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
示例#7
0
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                var rolesToDelete = await _roleRepository.Query().Include(x => x.UserRoles)
                                    .SingleOrDefaultAsync(x => x.Id == id);

                if (rolesToDelete == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                await _userRoleService.Delete(rolesToDelete.UserRoles.ToList());

                var entity = await _roleRepository.DeleteAsync(id);

                var resource = new RoleResource();
                response.Model   = _mapper.Map(entity, resource);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
示例#8
0
        public async Task <IActionResult> Update(int id, RoleResource resource)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                var role = await _roleRepository.FindAsync(x => x.Id == id);

                if (role == null || resource == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                _mapper.Map(resource, role);

                await _roleRepository.UpdateAsync(role);

                response.Model   = _mapper.Map(role, resource);
                response.Message = "The data was saved successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
示例#9
0
        public async Task <IActionResult> GetBookById(int bookId)
        {
            var response = new SingleModelResponse <BookModel>() as ISingleModelResponse <BookModel>;

            var query = await _bookService.GetBookByIdAsync(bookId);

            if (query == null)
            {
                _logger.Warning(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.GET_ITEM_NOTFOUND, "GET_ITEM_NOTFOUND", RequestPath());

                response.HasError     = true;
                response.ErrorMessage = "GET_ITEM_NOTFOUND";
                response.ErrorCode    = LoggingEvents.GET_ITEM_NOTFOUND;
                return(response.ToHttpResponse());
            }

            var result = new BookModel()
            {
                Id                = query.Id,
                Isbn              = query.Isbn,
                Name              = query.Name,
                Publisher         = query.Publisher,
                Stock             = query.Stock,
                Language          = query.Language,
                Hardcover         = query.Hardcover,
                Description       = query.Description,
                ProductDimensions = query.ProductDimensions
            };

            response.Model   = result;
            response.Message = string.Format("Total of records: {0}", 1);

            _logger.Information(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.GET_ITEM, "GET_ITEM", RequestPath());
            return(response.ToHttpResponse());
        }
示例#10
0
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <Partner>();

            try
            {
                var partner = _repository.Query()
                              .Include(x => x.PartnerContacts)
                              .FirstOrDefault(x => x.Id == id);

                if (partner == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                await _partnerContactRepository.DeleteRangeAsync(partner.PartnerContacts.ToList());

                var entity = await _repository.DeleteAsync(id);

                response.Model   = entity;
                response.Message = ResponseMessageConstants.Delete;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
示例#11
0
        public async Task <IActionResult> Create(AreaResource resource)
        {
            var response = new SingleModelResponse <AreaResource>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = "Input cannot be null.";
                return(response.ToHttpResponse());
            }

            try
            {
                var area = new Area();
                _mapper.Map(resource, area);

                var entity = await _areaRepository.AddAsync(area);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = "The data was saved successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
示例#12
0
        public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <AreaResource>();

            try
            {
                var entity = await _areaRepository.Query().Include(x => x.Functions)
                             .FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                var resource = new AreaResource();
                _mapper.Map(entity, resource);
                response.Model = resource;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Create(PartnerContactResource resource)
        {
            var response = new SingleModelResponse <PartnerContactResource>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }

            try
            {
                var entity = new PartnerContact();
                _mapper.Map(resource, entity);

                var entityAdded = await _repository.AddAsync(entity);

                response.Model   = _mapper.Map(entityAdded, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Create(CategoryBooking resource)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }

            try
            {
                var area = new CategoryBooking();
                _mapper.Map(resource, area);

                var entity = await _cateBookingRepository.AddAsync(area);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
示例#15
0
        public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <PartnerResource>();

            try
            {
                var entity = await _repository.Query()
                             .Include(x => x.GroupPartner)
                             .Include(x => x.PartnerContacts)
                             .FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                response.Model = _mapper.Map(entity, response.Model);
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            try
            {
                var entity = await _cateBookingRepository.Query().FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                var resource = new CategoryBooking();
                _mapper.Map(entity, resource);
                response.Model = resource;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
示例#17
0
        public async Task <IActionResult> BookReserve(int bookId, string userEmail)
        {
            var response = new SingleModelResponse <ReserveResultModel>() as ISingleModelResponse <ReserveResultModel>;

            try
            {
                var book = await _bookService.GetBookByIdAsync(bookId);

                var user = await _userService.GetUserByEmailAsync(userEmail);

                if (book.Stock != 0)
                {
                    book.Stock = book.Stock - 1;
                    await _bookService.UpdateBookAsync(book);

                    var rental = new Rental()
                    {
                        BookId      = bookId,
                        UserId      = user.Id,
                        ReserveDate = DateTime.Now,
                        ReturnDate  = DateTime.Now.AddDays(7),
                        Returned    = false
                    };
                    await _bookService.RentalInsertAsync(rental);

                    response.HasError = false;
                    response.Model    = new ReserveResultModel()
                    {
                        Result = "Successful for " + user.FirstName + " " + user.LastName
                    };

                    _logger.Information(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.GET_ITEM, "RESERVE SUCCESSFUL", RequestPath(), RequestPathString());
                    return(response.ToHttpResponse());
                }

                response.HasError = true;
                response.Model    = new ReserveResultModel()
                {
                    Result = "Unsuccessful"
                };
                response.ErrorMessage = "No stock for this book";

                _logger.Warning(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.GET_ITEM_NOTFOUND, "NO STOCK FOR THIS BOOK", RequestPath(), RequestPathString());
            }
            catch (Exception ex)
            {
                response.HasError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
示例#18
0
        public async Task <IActionResult> DeleteClub([FromQuery] int club)
        {
            var response = new SingleModelResponse <Club>()
                           as ISingleModelResponse <Club>;

            try
            {
                if (club.ToString() == null)
                {
                    throw new Exception("Model is missing");
                }
                response.Model = await Task.Run(() =>
                {
                    _context.Delete(club);
                    Club cclub = new Club
                    {
                        ClubId = club
                    };
                    return(cclub);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
示例#19
0
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <AreaResource>();

            try
            {
                var areaWithFunctions = await _areaRepository.Query().Include(x => x.Functions)
                                        .SingleOrDefaultAsync(x => x.Id == id);

                foreach (var function in areaWithFunctions.Functions)
                {
                    function.IdArea = null;
                }

                var entity = await _areaRepository.DeleteAsync(id);

                var resource = new AreaResource();
                response.Model   = _mapper.Map(entity, resource);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
示例#20
0
        public IActionResult Post([FromBody] UserType result)
        {
            var response = new SingleModelResponse <UserType>() as ISingleModelResponse <UserType>;

            try
            {
                if (ModelState.IsValid)
                {
                    _userType.Add(result);
                    _userType.Commit();

                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Success    = "Y";
                    response.Message    = "Save data successful.";
                }
                else
                {
                    response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    response.Success    = "N";
                    response.Message    = "Invalid entry.";
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                response.Success    = "N";
                response.Message    = ex.Message;
            }
            return(response.ToHttpResponse());
        }
示例#21
0
        public IActionResult Delete(int id)
        {
            var response = new SingleModelResponse <UserType>() as ISingleModelResponse <UserType>;

            try
            {
                var room = _userType.GetUserTypeById(id);
                if (room == null)
                {
                    response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    response.Message    = "Something went wrong when deleting data.";
                    response.Success    = "N";
                }
                else
                {
                    _userType.Remove(room);
                    _userType.Commit();

                    response.Message    = "Data successfully deleted.";
                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Success    = "Y";
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                response.Message    = ex.Message;
                response.Success    = "N";
            }
            return(response.ToHttpResponse());
        }
示例#22
0
        public IActionResult ChangePassword(int id, string oldPassword, string newPassword)
        {
            var response = new SingleModelResponse <Boolean>() as ISingleModelResponse <Boolean>;

            try
            {
                if (ModelState.IsValid)
                {
                    var data = _userService.changePassword(id, oldPassword, newPassword);
                    if (data)
                    {
                        var newUser = _userService.GetUserById(id);
                        newUser.password = newPassword;
                        _userService.Update(newUser);
                        _userService.Commit();
                    }
                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Success    = "Y";
                    response.Data       = data;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                response.Message    = ex.Message;
                response.Success    = "N";
                response.Data       = false;
            }
            return(response.ToHttpResponse());
        }
示例#23
0
        public async Task <IActionResult> CreateClub([FromBody] Club club)
        {
            var response = new SingleModelResponse <Club>()
                           as ISingleModelResponse <Club>;

            try
            {
                if (club == null)
                {
                    throw new Exception("Model is missing");
                }
                response.Model = await Task.Run(() =>
                {
                    Club cl = _context.AddClub(club);

                    return(cl);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
示例#24
0
        public async Task <IActionResult> GetClub([FromQuery] int clubId)
        {
            var response = new SingleModelResponse <Club>()
                           as ISingleModelResponse <Club>;

            try
            {
                if (clubId < 1)
                {
                    throw new Exception("Club Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    Club evnt = _context.GetClubByID(clubId);
                    if (evnt == null)
                    {
                        throw new Exception("Club does not Exist");
                    }
                    return(evnt);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
        public async Task<IActionResult> Create([FromBody] TodoItem item)
        {
            var response = new SingleModelResponse<TodoItem>() as ISingleModelResponse<TodoItem>;
            TodoItem itemJustInserted = null;

            if (item == null)
            {
                response.DidError = true;
                response.ErrorMessage = "Cannot pass null value";
            }

            try
            {
                itemJustInserted = _todoRepository.Add(item);
                response.Message = "Inserted Successfully!";
            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.ToString();
            }

            response.Model = _todoRepository.Find(itemJustInserted.Key);

            return response.ToHttpResponse();
        }
        public async Task<IActionResult> GetById(int id)
        {
            var response = new SingleModelResponse<TodoItem>() as ISingleModelResponse<TodoItem>;
            try
            {
                var item = _todoRepository.Find(id);
                if (item == null)
                {
                    response.DidError = true;
                    response.ErrorMessage = "Value cannot be null";
                }
                else
                {
                    response.Model = item;
                }

            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.Message;
            }

            return response.ToHttpResponse();

            //var item = _todoRepository.Find(id);
            //if (item == null)
            //{
            //    return NotFound();
            //}
            //return new ObjectResult(item);
        }
        public IActionResult Delete(int id)
        {
            var response = new SingleModelResponse<TodoItem>() as ISingleModelResponse<TodoItem>;

            try
            {

                var todo = _todoRepository.Find(id);
                if (todo == null)
                {
                    return NotFound();
                }

                response.Message = "Deleted Successfully!";
                _todoRepository.Remove(id);

            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.Message;
            }

            return response.ToHttpResponse();

            //var todo = _todoRepository.Find(id);
            //if (todo == null)
            //{
            //    return NotFound();
            //}

            //_todoRepository.Remove(id);
            //return new NoContentResult();
        }
示例#28
0
        public async Task <IActionResult> DeleteRoute([FromQuery] int routeId)
        {
            var response = new SingleModelResponse <Route>()
                           as ISingleModelResponse <Route>;

            try
            {
                if (routeId.ToString() == null)
                {
                    throw new Exception("Route Model is missing");
                }
                response.Model = await Task.Run(() =>
                {
                    _context.DeleteRoute(routeId);
                    Route route   = new Route();
                    route.RouteId = routeId;
                    return(route);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
示例#29
0
        public async Task <IActionResult> GetRoute([FromQuery] int routeId)
        {
            var response = new SingleModelResponse <Route>()
                           as ISingleModelResponse <Route>;

            try
            {
                if (routeId < 1)
                {
                    throw new Exception("Route Id is missing");
                }
                response.Model = await Task.Run(() =>
                {
                    Route route = _context.GetRouteByID(routeId);
                    if (route == null)
                    {
                        throw new Exception("Route does not exist");
                    }
                    return(route);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
示例#30
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> AddRoute([FromBody] Route route, [FromQuery] string userId)
        {
            var response = new SingleModelResponse <Route>()
                           as ISingleModelResponse <Route>;

            try
            {
                if (route == null && userId == null)
                {
                    throw new Exception("Your whole request is messed up. Route and UserId missing");
                }
                else if (route == null)
                {
                    throw new Exception("Route is missing");
                }
                else if (userId == null)
                {
                    throw new Exception("User ID is missing");
                }
                response.Model = await Task.Run(() =>
                {
                    route.UserID   = userId;
                    Route newRoute = _context.AddRoute(route);


                    return(newRoute);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
        public async Task<HttpResponseMessage> GetWorkflow(Int32 id)
        {
            var response = new SingleModelResponse<WorkflowViewModel>() as ISingleModelResponse<WorkflowViewModel>;

            try
            {
                var model = await Task.Run(() =>
                {
                    return BusinessObject.GetWorkflow(new Workflow { ID = id });
                });

                response.Model = new WorkflowViewModel(model);
            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.Message;
            }

            return response.ToHttpResponse(Request);
        }
        public async Task<HttpResponseMessage> CreateWorkflow([FromBody]WorkflowViewModel value)
        {
            var response = new SingleModelResponse<WorkflowViewModel>() as ISingleModelResponse<WorkflowViewModel>;

            try
            {
                var model = await Task.Run(() =>
                {
                    return BusinessObject.AddWorkflow(value.ToEntity());
                });

                response.Model = new WorkflowViewModel(model);
            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.Message;
            }

            return response.ToHttpResponse(Request);
        }