Beispiel #1
0
        public ActionResult CarbCountingUpdate(CarbCountingVM model, IEnumerable <HttpPostedFileBase> file)
        {
            try
            {
                string physicalPath = "~/images/CarbCounting/";
                int    maxFileSize  = 500000;

                Dictionary <FileResultItem, FileResultType> resultModel = FileDocumentUpload(file, maxFileSize, physicalPath, new string[] { "image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/bmp", "image/x-png", "image/jpg" });

                foreach (var item in resultModel)
                {
                    if (item.Value == FileResultType.Error || item.Value == FileResultType.NoneFile || item.Value == FileResultType.SizeOver || item.Value == FileResultType.WrongType)
                    {
                        RemoveAll(resultModel.Keys, physicalPath);
                        TempData["NoteCss"]  = "warning";
                        TempData["NoteText"] = ControlMessages(item.Value, maxFileSize).Keys.FirstOrDefault().ToString();

                        return(View("CarbCountingUpdate"));
                    }
                }

                foreach (var item in resultModel.Keys)
                {
                    model.carbohydrateCounting.ImageURL = item.UploadPath;
                }
            }
            catch (Exception ex)
            {
                TempData["NoteCss"]   = "danger";
                TempData["NoteText"]  = "Bilinmeyen Hata!";
                TempData["NoteError"] = ex.Message;
            }
            model.carbohydrateCounting.IsActive    = true;
            model.carbohydrateCounting.UpdatedDate = DateTime.Now;
            model.carbohydrateCounting.CreatedDate = DateTime.Now;
            model.carbohydrateCounting.CreatedByID = 1;

            var oldCarbCounting = _unitOfWork.CarbohydrateCountingRepository.Find(x => x.ID == model.carbohydrateCounting.ID);

            if (ModelState.IsValid)
            {
                List <FileResultItem> fileResultItems = new List <FileResultItem> {
                    new FileResultItem {
                        UploadPath = oldCarbCounting.ImageURL
                    }
                };
                RemoveAll(fileResultItems, "~/images/CarbCounting/");
                _unitOfWork.CarbohydrateCountingRepository.Detach(oldCarbCounting);
                _unitOfWork.CarbohydrateCountingRepository.Update(model.carbohydrateCounting);
                _unitOfWork.Save();
            }
            return(RedirectToAction("CarbCountingList"));
        }
 public HomeController()
 {
     _unitOfWork     = new UnitOfWork();
     _contactUsVM    = new ContactUsVM();
     _carbCountingVM = new CarbCountingVM();
     _diaEduVM       = new DiaEduVM();
     _list           = new List <DiabetesEducation>();
     _homeVM         = new HomeVM();
     _newsVM         = new NewsVM();
     _newsVMs        = new List <NewsVM>();
     _newsList       = new List <News>();
     _titleNewsList  = new List <News>();
     _titleDiaList   = new List <DiabetesEducation>();
     _eventVM        = new Areas.Admin.Models.EventVM();
     _eventVMs       = new List <Areas.Admin.Models.EventVM>();
 }
Beispiel #3
0
        public ActionResult CarbCountingAdd(CarbCountingVM model, IEnumerable <HttpPostedFileBase> file)
        {
            try
            {
                string physicalPath = "~/images/CarbCounting/";
                int    maxFileSize  = 500000;

                Dictionary <FileResultItem, FileResultType> resultModel = FileDocumentUpload(file, maxFileSize, physicalPath, new string[] { "image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/bmp", "image/x-png", "image/jpg" });

                foreach (var item in resultModel)
                {
                    if (item.Value == FileResultType.Error || item.Value == FileResultType.NoneFile || item.Value == FileResultType.SizeOver || item.Value == FileResultType.WrongType)
                    {
                        RemoveAll(resultModel.Keys, physicalPath);
                        TempData["NoteCss"]  = "warning";
                        TempData["NoteText"] = ControlMessages(item.Value, maxFileSize).Keys.FirstOrDefault().ToString();

                        return(View("CarbCountingAdd"));
                    }
                }

                foreach (var item in resultModel.Keys)
                {
                    _unitOfWork.CarbohydrateCountingRepository.Insert(new CarbohydrateCounting {
                        Title = model.carbohydrateCounting.Title, ImageURL = item.UploadPath, Description = model.carbohydrateCounting.Description, CreatedDate = DateTime.Now
                    });
                    _unitOfWork.Save();
                }
            }
            catch (Exception ex)
            {
                TempData["NoteCss"]   = "danger";
                TempData["NoteText"]  = "Bilinmeyen Hata!";
                TempData["NoteError"] = ex.Message;
            }
            return(RedirectToAction("CarbCountingList"));
        }
Beispiel #4
0
 public CarbCountingController()
 {
     _unitOfWork     = new UnitOfWork();
     _carbCountingVM = new CarbCountingVM();
 }