Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public ActionResult AddRecepi([FromBody] RecepiVM recepiVM)
 {
     try
     {
         var recepi = _recepiService.AddRecepi(recepiVM);
         return(Ok(recepi));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 3
0
 public ActionResult GetRecepiById([FromBody] RecepiVM recepiVM)
 {
     try
     {
         var recepies = _recepiService.GetRecepiById(recepiVM.RecepiId);
         return(Ok(recepies));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }