示例#1
0
        public async Task <IActionResult> EditSection(int id, [FromForm] SectionUpdateDTO section)
        {
            var sectionFromDb = await _repo.GetOneWithConditionTracking <Section>(section => section.Id == id);

            if (sectionFromDb == null)
            {
                return(NotFound());
            }
            _mapper.Map(section, sectionFromDb);
            if (section.File != null)
            {
                if (!string.IsNullOrEmpty(sectionFromDb.PublicId))
                {
                    var deleteResult = _cloud.DeleteImage(sectionFromDb.PublicId);
                    if (deleteResult)
                    {
                        var uploadResult = _cloud.UploadImage(section.File);
                        if (uploadResult != null)
                        {
                            sectionFromDb.PublicId = uploadResult.PublicId;
                            sectionFromDb.PhotoUrl = uploadResult.PublicUrl;
                        }
                    }
                }
            }
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(StatusCode(500));
        }
示例#2
0
 public ActionResult <SectionCreateDTO> SectionDelete(SectionUpdateDTO s)
 {
     try
     {
         return(Ok(SqlSectionsRepository.SectionDelete(s.id)));
     }
     catch (DatabaseException)
     {
         return(StatusCode(500));
     }
 }
示例#3
0
 public ActionResult <SectionUpdateDTO> SectionUpdate(SectionUpdateDTO s)
 {
     try
     {
         return(Ok(SqlSectionsRepository.SectionUpdate(s.id, s.uc, s.semester, s.ht, s.hp, s.hl, s.name,
                                                       s.description, s.type, s.fk_school)));
     }
     catch (DatabaseException)
     {
         return(StatusCode(500));
     }
 }