Example #1
0
        public ActionResult Create(TreatmentDetails treatmentDetails, HttpPostedFileBase file)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                string     filePath = cldSetup.SaveToCloud(file);
                ImageFiles imgFile  = new ImageFiles();
                string     fileGuid = Guid.NewGuid().ToString();

                imgFile.ContentType = System.IO.Path.GetExtension(file.FileName);
                imgFile.FileName    = System.IO.Path.GetFileName(file.FileName);
                imgFile.FilePath    = filePath;
                imgFile.Size        = file.InputStream.Length;
                imgFile.FileGuid    = fileGuid;

                context.ImageFiles.Add(imgFile);
                context.SaveChanges();

                var maxOrderId = context.TreatmentDetails.Max(c => c.OrderId);
                maxOrderId = maxOrderId == null ? 1 : maxOrderId + 1;
                treatmentDetails.CreatedDate = DateTime.Now;
                treatmentDetails.ImageId     = fileGuid;
                treatmentDetails.OrderId     = maxOrderId;
                context.TreatmentDetails.Add(treatmentDetails);
                context.SaveChanges();
                scope.Complete();
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        public ActionResult AddImages(SliderImages sldrImages, IEnumerable <HttpPostedFileBase> files)
        {
            if (files != null)
            {
                CloudiNarySetup cldNSetup = new CloudiNarySetup();
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var file in files)
                    {
                        string filePath = cldNSetup.SaveToCloud(file);

                        string     fileGuid = Guid.NewGuid().ToString();
                        ImageFiles imgFiles = new ImageFiles();
                        imgFiles.ContentType = Path.GetExtension(file.FileName);
                        imgFiles.FileGuid    = fileGuid;
                        imgFiles.FileName    = file.FileName;
                        imgFiles.FilePath    = filePath;
                        imgFiles.Size        = file.ContentLength;

                        context.ImageFiles.Add(imgFiles);
                        context.SaveChanges();

                        sldrImages.ImageId     = fileGuid;
                        sldrImages.CreatedDate = DateTime.Now;
                        context.SliderImages.Add(sldrImages);
                        context.SaveChanges();
                    }
                    scope.Complete();
                }
            }
            return(RedirectToAction("Index"));
        }