public ActionResult UploadImages()
        {
            var finalFileNames = new List <string>();

            try
            {
                foreach (string fileName in Request.Files)
                {
                    var image       = Request.Files[fileName];
                    var newFileName = FileUploadManager.UploadAndSave(image);

                    finalFileNames.Add(newFileName);
                }

                return(new JsonResult
                {
                    Data = new { FileNames = finalFileNames }
                });
            }
            catch (Exception ex)
            {
                ex.Log();

                finalFileNames.ForEach(a => FileUploadManager.DeleteFile(a));

                return(new JsonResult
                {
                    Data = new { Error = ex.Message }
                });
            }
        }
        public ActionResult Index(HttpPostedFileBase file, MemberEditViewModel viewModel)
        {
            var member = db.tblmembers.Single(a => a.ID == viewModel.ID);

            member.BusinessRegNo = viewModel.BusinessRegNo;
            member.CompanyName   = viewModel.CompanyName;
            member.PICName       = viewModel.PICName;
            member.PICContact    = viewModel.PICContact;
            //member.PICEmail = viewModel.PICEmail;
            member.Address  = viewModel.Address;
            member.Postcode = viewModel.Postcode;
            member.State    = viewModel.State;
            member.Country  = viewModel.Country;
            //member.Active = viewModel.Active;

            if (file != null)
            {
                var fileName = FileUploadManager.UploadAndSave(file);
                member.ProfileImagePath = fileName;
            }

            db.SaveChanges();

            Util.SessionAccess = member;

            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult Register(HttpPostedFileBase file, RegisterViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var exists = db.tblmembers.Any(a => a.Active && a.PICEmail == viewModel.Email);

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Invalid email.");
                return(View(viewModel));
            }

            var member = new tblmember()
            {
                PICName  = viewModel.Name,
                PICEmail = viewModel.Email,
                Roles    = "NU",
                Password = Util.GetMD5Hash(viewModel.Password),
                CreateDT = DateTime.Now,
                Language = "EN",
                Active   = true
            };

            if (file != null)
            {
                var fileName = FileUploadManager.UploadAndSave(file);
                member.ProfileImagePath = fileName;
            }

            db.tblmembers.Add(member);
            db.SaveChanges();

            var emailBody = string.Format(@"Hi {0}, <br /><br />
                    Thanks for Subscribing to the EZ Go Holiday Website ! You’re joining an amazing community of folks who love nerding out about travelling. <br /><br />
                    As you wait for the next issue, check out some of our most popular posts. They’re a great place to get started. <br /><br />
                    Website: http://www.ezgoholiday.com <br />
                    Username: {1} <br />
                    Password: {2} <br /><br />

                    Have an awesome day! <br />
                    EZ Go Holiday Management",
                                          viewModel.Name, viewModel.Email, viewModel.Password);

            Util.SendEmail("Welcome to EZ Go Holiday!", emailBody, viewModel.Email, "", "");

            Util.SessionAccess = member;
            FormsAuthentication.SetAuthCookie(viewModel.Email, false);

            return(RedirectToAction("Index", "Home"));
        }
示例#4
0
        public ActionResult Create(HttpPostedFileBase file, BlogCreateViewModel viewModel)
        {
            if (!ModelState.IsValid || file == null)
            {
                if (file == null)
                {
                    ModelState.AddModelError("", "Thumbnail is required.");
                }

                viewModel.Categories = GetList(ListType.Category);
                return(View(viewModel));
            }

            var blog = new trnblog()
            {
                Body       = viewModel.Body,
                CreateDT   = DateTime.Now,
                CategoryID = viewModel.CategoryID,
                Language   = lang,
                MemberID   = Util.SessionAccess.ID,
                PublishDT  = DateTime.Now,
                Title      = viewModel.Title,
                Active     = true
            };

            if (file != null)
            {
                var fileName = FileUploadManager.UploadAndSave(file);
                blog.ThumbnailImagePath = fileName;
            }

            db.trnblogs.Add(blog);
            db.SaveChanges();

            var emailBody = string.Format(@"Hi EZ Management, <br /><br />
                    New blog <b>{0}</b> has been created. <br /><br />
                    
                    http://www.ezgoholiday.com/EN/Blog/Details/{1}",
                                          viewModel.Title, blog.ID);

            Util.SendEmail(viewModel.Title, emailBody, Properties.Settings.Default.EmailFrom, "", "");

            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult Edit(HttpPostedFileBase file, BlogEditViewModel viewModel)
        {
            var blog = db.trnblogs.Single(a => a.ID == viewModel.ID);

            if (!ModelState.IsValid)
            {
                viewModel.ThumbnailImagePath =
                    string.IsNullOrEmpty(blog.ThumbnailImagePath) ?
                    "" : Path.Combine(Settings.Default.ImageUploadPath, blog.ThumbnailImagePath);
                viewModel.Categories = GetList(ListType.Category);
                return(View(viewModel));
            }

            blog.CategoryID = viewModel.CategoryID;
            blog.Title      = viewModel.Title;
            blog.Body       = viewModel.Body;
            blog.UpdateDT   = DateTime.Now;
            blog.Active     = viewModel.Active;

            if (file != null)
            {
                var fileName = FileUploadManager.UploadAndSave(file);
                blog.ThumbnailImagePath = fileName;
            }

            db.SaveChanges();

            var emailBody = string.Format(@"Hi EZ Management, <br /><br />
                    Blog <b>{0}</b> has been updated. <br /><br />
                    
                    http://www.ezgoholiday.com/EN/Blog/Details/{1}",
                                          viewModel.Title, blog.ID);

            Util.SendEmail(viewModel.Title, emailBody, Properties.Settings.Default.EmailFrom, "", "");

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(HttpPostedFileBase file, PackageCreateViewModel viewModel)
        {
            if (!ModelState.IsValid || file == null)
            {
                if (file == null)
                {
                    ModelState.AddModelError("", "Thumbnail is required.");
                }

                viewModel.Categories       = GetList(ListType.Category);
                viewModel.Countries        = GetList(ListType.Country, defaultItem: false);
                viewModel.Activities       = GetPackageActivities();
                viewModel.DetailImageNames = "";

                return(View(viewModel));
            }

            var postID = 0;

            var isAvailable = CheckAvailablePost(Util.SessionAccess.ID);

            using (var trans = new TransactionScope())
            {
                var post = new lnkmemberpost()
                {
                    Description = viewModel.Description,
                    CreateDT    = DateTime.Now,
                    Language    = lang,
                    MemberID    = Util.SessionAccess.ID,
                    PublishDT   = DateTime.Now,
                    Title       = viewModel.Title,
                    CategoryID  = viewModel.CategoryID,
                    Price       = viewModel.Price,
                    StartDT     = viewModel.StartDT,
                    EndDT       = viewModel.EndDT,
                    Days        = viewModel.Days,
                    Nights      = viewModel.Nights,
                    Active      = isAvailable,
                };

                if (file != null)
                {
                    var fileName = FileUploadManager.UploadAndSave(file);
                    post.ThumbnailImagePath = fileName;
                }

                db.lnkmemberposts.Add(post);
                db.SaveChanges();

                if (!viewModel.CountryIDs.IsEmpty())
                {
                    var memberCountries =
                        viewModel.CountryIDs
                        .Select(a =>
                                new lnkmemberpostcountry
                    {
                        Active       = true,
                        CountryID    = a,
                        CreateDT     = DateTime.Now,
                        MemberPostID = post.ID
                    })
                        .ToArray();

                    db.lnkmemberpostcountries.AddRange(memberCountries);
                }

                if (!viewModel.SelectedActivities.IsEmpty())
                {
                    foreach (var activityID in viewModel.SelectedActivities)
                    {
                        var activity = new lnkmemberpostpackageactivity
                        {
                            Active            = true,
                            CreateDT          = DateTime.Now,
                            MemberPostID      = post.ID,
                            PackageActivityID = activityID
                        };
                        db.lnkmemberpostpackageactivities.Add(activity);
                    }
                    db.SaveChanges();
                }

                if (!string.IsNullOrEmpty(viewModel.DetailImageNames))
                {
                    var detailImages = viewModel.DetailImageNames.Split(',');

                    foreach (var image in detailImages)
                    {
                        var linkImage = new lnkmemberpostimage
                        {
                            Active       = true,
                            CreateDT     = DateTime.Now,
                            ImagePath    = image,
                            MemberPostID = post.ID,
                        };
                        db.lnkmemberpostimages.Add(linkImage);
                    }
                    db.SaveChanges();
                }

                trans.Complete();

                postID = post.ID;
            }

            var emailBody = string.Format(@"Hi EZ Management, <br /><br />
                    Package <b>{0}</b> has been created. <br /><br />
                    
                    http://ezgoholiday.com/EN/Package/Details/{1} <br /><br />
                    Posted: {2}",
                                          viewModel.Title, postID, isAvailable);

            Util.SendEmail(viewModel.Title, emailBody, Properties.Settings.Default.EmailFrom, "", "");


            if (viewModel.Active && !isAvailable)
            {
                return(RedirectToAction("Edit", new
                {
                    id = postID,
                    errorMessage = "不足够可发布数量.\n帖子成功保存,但无法发布到网站."
                }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Edit(HttpPostedFileBase file, PackageEditViewModel viewModel)
        {
            var isAvailable = CheckAvailablePost(Util.SessionAccess.ID);

            using (var trans = new TransactionScope())
            {
                var package = db.lnkmemberposts.Single(a => a.ID == viewModel.ID);
                package.Title       = viewModel.Title;
                package.Description = viewModel.Description;
                package.UpdateDT    = DateTime.Now;
                package.Price       = viewModel.Price;
                package.CategoryID  = viewModel.CategoryID;
                package.StartDT     = viewModel.StartDT;
                package.EndDT       = viewModel.EndDT;
                package.Days        = viewModel.Days;
                package.Nights      = viewModel.Nights;
                package.Active      = viewModel.Active ? isAvailable : viewModel.Active;

                if (file != null)
                {
                    var fileName = FileUploadManager.UploadAndSave(file);
                    package.ThumbnailImagePath = fileName;
                }

                var oldCountries = db.lnkmemberpostcountries.Where(a => a.MemberPostID == viewModel.ID && a.Active).ToList();
                oldCountries.ForEach(a => a.Active = false);
                db.SaveChanges();

                if (!viewModel.CountryIDs.IsEmpty())
                {
                    foreach (var countryID in viewModel.CountryIDs)
                    {
                        var inactiveAct = db.lnkmemberpostcountries
                                          .SingleOrDefault(a => a.CountryID == countryID && a.MemberPostID == viewModel.ID);

                        if (inactiveAct == null)
                        {
                            var country = new lnkmemberpostcountry
                            {
                                Active       = true,
                                CreateDT     = DateTime.Now,
                                MemberPostID = viewModel.ID,
                                CountryID    = countryID
                            };
                            db.lnkmemberpostcountries.Add(country);
                        }
                        else
                        {
                            inactiveAct.Active = true;
                        }
                    }
                    db.SaveChanges();
                }

                var oldActivities = db.lnkmemberpostpackageactivities.Where(a => a.MemberPostID == viewModel.ID && a.Active).ToList();
                oldActivities.ForEach(a => a.Active = false);
                db.SaveChanges();

                if (!viewModel.SelectedActivities.IsEmpty())
                {
                    foreach (var activityID in viewModel.SelectedActivities)
                    {
                        var inactiveAct = db.lnkmemberpostpackageactivities
                                          .SingleOrDefault(a => a.PackageActivityID == activityID && a.MemberPostID == viewModel.ID);

                        if (inactiveAct == null)
                        {
                            var activity = new lnkmemberpostpackageactivity
                            {
                                Active            = true,
                                CreateDT          = DateTime.Now,
                                MemberPostID      = viewModel.ID,
                                PackageActivityID = activityID
                            };
                            db.lnkmemberpostpackageactivities.Add(activity);
                        }
                        else
                        {
                            inactiveAct.Active = true;
                        }
                    }
                    db.SaveChanges();
                }

                var existingDetailImages = db.lnkmemberpostimages.Where(a => a.Active && a.MemberPostID == viewModel.ID).ToList();
                var detailImages         = viewModel.DetailImageNames?.Split(',').ToList() ?? new List <string>();

                foreach (var existingImage in existingDetailImages)
                {
                    if (detailImages.Contains(existingImage.ImagePath))
                    {
                        detailImages.Remove(existingImage.ImagePath);
                    }
                    else
                    {
                        existingImage.Active   = false;
                        existingImage.UpdateDT = DateTime.Now;
                    }
                }

                foreach (var image in detailImages)
                {
                    var linkImage = new lnkmemberpostimage
                    {
                        Active       = true,
                        CreateDT     = DateTime.Now,
                        ImagePath    = image,
                        MemberPostID = viewModel.ID,
                    };
                    db.lnkmemberpostimages.Add(linkImage);
                }
                db.SaveChanges();

                trans.Complete();
            }

            var emailBody = string.Format(@"Hi EZ Management, <br /><br />
                    Package <b>{0}</b> has been created. <br /><br />
                    
                    http://ezgoholiday.com/EN/Package/Details/{1}",
                                          viewModel.Title, viewModel.ID);

            Util.SendEmail(viewModel.Title, emailBody, Properties.Settings.Default.EmailFrom, "", "");

            if (viewModel.Active && !isAvailable)
            {
                return(RedirectToAction("Edit", new
                {
                    id = viewModel.ID,
                    errorMessage = "不足够可发布数量.\n帖子成功保存,但无法发布到网站."
                }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }