Ejemplo n.º 1
0
 public IHttpActionResult Put(SubDivisionDTO subDivisionDTO)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid model"));
     }
     subDivisionService.Put(subDivisionDTO);
     return(Ok());
 }
Ejemplo n.º 2
0
 public void Create(SubDivisionDTO subDivisionDTO)
 {
     using (var db = new ModelContext())
     {
         SubDivision subDivision = db.SubDivisions.Create();
         subDivision.Name       = subDivisionDTO.Name;
         subDivision.DivisionId = subDivisionDTO.DivisionId;
         db.SubDivisions.Add(subDivision);
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void Put(SubDivisionDTO subDivisionDTO)
 {
     using (var db = new ModelContext())
     {
         SubDivision existingSubDivision = db.SubDivisions
                                           .Where(m => m.Id == subDivisionDTO.Id)
                                           .FirstOrDefault();
         if (existingSubDivision != null)
         {
             existingSubDivision.Name       = subDivisionDTO.Name;
             existingSubDivision.DivisionId = subDivisionDTO.DivisionId;
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 4
0
        public SubDivisionDTO GetSubDivisionByDivision(int divisionId, int id)
        {
            using (var db = new ModelContext())
            {
                List <SubDivision>    subDivisions = db.SubDivisions.Where(m => m.DivisionId == divisionId && m.Id == id).ToList();
                List <SubDivisionDTO> dtos         = new List <SubDivisionDTO>();

                foreach (var subDivision in subDivisions)
                {
                    SubDivisionDTO dto = new SubDivisionDTO();
                    dto.Id            = subDivision.Id;
                    dto.Name          = subDivision.Name;
                    dto.DivisionId    = subDivision.DivisionId;
                    dto.CategoriesIds = subDivision.Categories
                                        .Select(m => m.Id)
                                        .ToList();
                    dtos.Add(dto);
                }
                return(dtos.FirstOrDefault());
            }
        }
Ejemplo n.º 5
0
        public List <SubDivisionDTO> GetAll()
        {
            using (var db = new ModelContext())
            {
                List <SubDivision>    subDivisions = db.SubDivisions.ToList();
                List <SubDivisionDTO> dtos         = new List <SubDivisionDTO>();

                foreach (var subDivision in subDivisions)
                {
                    SubDivisionDTO dto = new SubDivisionDTO();
                    dto.Id            = subDivision.Id;
                    dto.Name          = subDivision.Name;
                    dto.DivisionId    = subDivision.DivisionId;
                    dto.CategoriesIds = subDivision.Categories
                                        .Select(m => m.Id)
                                        .ToList();
                    dtos.Add(dto);
                }
                return(dtos);
            }
        }