public IActionResult AddEditSubTopic([FromForm] TopicCommonRequestModel model) { ResponseModel responseModel = new ResponseModel(); if (ModelState.IsValid) { if (model.Id == 0) { SubTopic subTopic = new SubTopic(); subTopic.TopicId = model.TopicId; subTopic.Name = model.Name; subTopic.Description = model.Description; subTopic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); subTopic.VideoLink = _fileService.SaveFile(model.Video, ClassBookConstant.VideoPath_Topic); subTopic.DateOfUpload = DateTime.Now; subTopic.DateOfActivation = model.DateOfActivation; subTopic.Deleted = false; subTopic.Active = true; _context.SubTopic.Add(subTopic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } else { var subTopic = _context.SubTopic.Where(x => x.Id == model.Id).FirstOrDefault(); subTopic.Name = model.Name; subTopic.Description = model.Description; subTopic.DateOfActivation = model.DateOfActivation; if (model.Files.Count > 0) { subTopic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); } if (model.Video.Count > 0) { subTopic.VideoLink = _fileService.SaveFile(model.Video, ClassBookConstant.VideoPath_Topic); } _context.SubTopic.Update(subTopic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } } else { return(StatusCode((int)HttpStatusCode.BadRequest, ModelState)); } }
public IActionResult AddEditTopic([FromForm] TopicCommonRequestModel model) { ResponseModel responseModel = new ResponseModel(); if (ModelState.IsValid) { if (model.Id == 0) { // Adding New Topic Topic topic = new Topic(); topic.OrderItemId = model.OrderItemId; topic.Name = model.Name; topic.Description = model.Description; if (model.Files != null && model.Files.Count > 0) { topic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); } topic.Deleted = false; topic.Active = true; _context.Topic.Add(topic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } else { var topic = _context.Topic.Where(x => x.Id == model.Id).FirstOrDefault(); topic.Name = model.Name; topic.Description = model.Description; if (model.Files.Count > 0) { topic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); } _context.Topic.Update(topic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } } else { return(StatusCode((int)HttpStatusCode.BadRequest, ModelState)); } }