public Fwbs Create(Fwbs fwbs) { if (string.IsNullOrEmpty(fwbs.Name)) { throw new ArgumentException("FWBS Name should not be empty "); } if (_context.FWBS.Any(x => x.Name == fwbs.Name)) { throw new AppException("FWBS name is already Exists"); } //if(fwbs.MediaID==0) //{ // throw new AppException("Media Is not Cretaed "); //} if (fwbs.CreatedOn == null) { fwbs.CreatedOn = DateTime.Now; } if (fwbs.ModifiedOn == null) { fwbs.ModifiedOn = DateTime.Now; } _context.FWBS.Add(fwbs); _context.SaveChanges(); return(fwbs); }
public Fwbs Save(Fwbs fwbs) { var fwbsData = (from f in _context.FWBS where f.Name == fwbs.Name select f).FirstOrDefault(); if (fwbsData.ID == fwbs.ID) { if (!string.IsNullOrEmpty(fwbs.Name)) { fwbsData.Name = fwbs.Name; } if (fwbs.MediaID == 0) { throw new AppException("Media Is not Cretaed "); } else { fwbsData.MediaID = fwbs.MediaID; } if (fwbs.CreatedOn == null) { fwbs.CreatedOn = DateTime.Now; } if (fwbs.ModifiedOn == null) { fwbs.ModifiedOn = DateTime.Now; } } _context.FWBS.Update(fwbs); _context.SaveChanges(); return(fwbs); }
public IActionResult Addfile([FromBody] FwbsUploadImageDto file) { // var media = _mapper.Map<Media>(file); string localPath = "\\Media\\"; switch (file.FileType) { case "Image": localPath = "\\Media\\Image\\"; break; default: break; } Media media = new Media() { Name = file.ImageName, Extention = file.Extension, FileType = file.FileType, Body = file.Body }; string path = _hostingEnvironment.ContentRootPath + localPath; var dataFromHelper = MediaHelperClass.CreateMedia(media, path); var data = _mediaService.create(dataFromHelper); Fwbs fwbsInfo = new Fwbs() { Name = file.Name, MediaID = data.ID }; var createData = _service.Save(fwbsInfo); return(Ok(createData)); }