Ejemplo n.º 1
0
        public IHttpActionResult Delete(int departmentid)
        {
            var repository = new RepositoryDepartments();
            var response   = repository.Delete(departmentid);

            return(Ok <DataResponse>(response));
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetDepartmentById(int?Id)
        {
            var response   = new DataResponse <EntityDepartments>();
            var repository = new RepositoryDepartments();

            if (Id.HasValue)
            {
                response = repository.GetDepartmentById(Id.Value);
            }
            else
            {
                response.Model = new EntityDepartments();
            }
            return(Ok <DataResponse>(response));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetByFilter(FilterDepartments filter)
        {
            var repository = new RepositoryDepartments();

            if (filter == null)
            {
                filter = new FilterDepartments {
                    PageSize = 25, CurrentPage = 1
                }
            }
            ;
            var response = repository.GetDepartments(filter, CurrentBusinessId.Value);

            return(Ok <DataResponse <EntityList <EntityDepartments> > >(response));
        }
Ejemplo n.º 4
0
        public IHttpActionResult InsertDepartmentData(VMDepartment model)
        {
            var response = new DataResponse <EntityDepartments>();

            if (ModelState.IsValid)
            {
                var entityDepartment = new EntityDepartments
                {
                    Id                     = model.Id,
                    DepartmentName         = model.DepartmentName,
                    Description            = model.Description,
                    DepartmentPrivilegeIds = model.DepartmentPrivilegeIds,
                    IsActive               = model.IsActive,
                };
                entityDepartment.UpdatedBy  = entityDepartment.CreatedBy = CurrentUserId;
                entityDepartment.BusinessId = CurrentBusinessId;
                if (model.Id > 0)
                {
                    response = new RepositoryDepartments().Update(entityDepartment);
                }
                else
                {
                    response = new RepositoryDepartments().Insert(entityDepartment);
                }
                return(Ok <DataResponse>(response));
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
        }