public ResponseVM AddRecepi(RecepiVM recepiVM) { ResponseVM responseVM = new ResponseVM(); //if (file.Length == 0 || file != null) //{ // responseVM.IsSuccess = false; // responseVM.Message = "File not found"; // return responseVM; //} //if (!ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(file.FileName).ToLower())) //{ // responseVM.IsSuccess = false; // responseVM.Message = "File format not proper"; // return responseVM; //} //var uploadFilesPath = Path.Combine(host.WebRootPath, "RecepiImages"); //if (!Directory.Exists(uploadFilesPath)) // Directory.CreateDirectory(uploadFilesPath); //var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); //var filePath = Path.Combine(uploadFilesPath, fileName); //using (var stream = new FileStream(filePath, FileMode.Create)) //{ // file.CopyTo(stream); //} if (recepiVM != null) { if (recepiVM.RecepiId > 0) { var data = new Recepi { RecepiId = recepiVM.RecepiId, RecepiName = recepiVM.RecepiName, RecepiDesc = recepiVM.RecepiDesc //RecepiImage = fileName }; _dbContext.Recepies.Update(data); } else { var data = new Recepi { RecepiName = recepiVM.RecepiName, RecepiDesc = recepiVM.RecepiDesc //RecepiImage = fileName }; _dbContext.Recepies.Add(data); } _dbContext.SaveChanges(); } responseVM.IsSuccess = true; responseVM.Message = "Recepi added successfully"; return(responseVM); }
public ActionResult AddRecepi([FromBody] RecepiVM recepiVM) { try { var recepi = _recepiService.AddRecepi(recepiVM); return(Ok(recepi)); } catch (Exception ex) { throw ex; } }
public ActionResult GetRecepiById([FromBody] RecepiVM recepiVM) { try { var recepies = _recepiService.GetRecepiById(recepiVM.RecepiId); return(Ok(recepies)); } catch (Exception ex) { throw ex; } }