示例#1
0
        public ActionResult Edit(int aId = 0, int gId = 0)
        {
            if (aId <= 0 && gId <= 0)
            {
                return(RedirectToAction("Index"));
            }
            var cVM = new CoachingVM();

            try
            {
                var games        = db.esc_games.ToList();
                var serviceTypes = new SelectList(db.esc_serviceTypes.ToList(), "Id", "Name");
                ViewBag.DBGames            = games;
                ViewData["DBServiceTypes"] = serviceTypes;
                ViewBag.DBHours            = PriceHourModel.GetPriceHours().ToList();

                var pGame = db.esc_profilegames.Where(x => x.gameId == gId && x.accountId == aId).FirstOrDefault();
                if (pGame == null)
                {
                    return(View());
                }

                var faqs     = db.esc_faq.Where(x => x.gameId == gId && x.accountId == aId).ToList();
                var pricings = db.esc_profilegamesPricing.Where(x => x.gameId == gId && x.accountId == aId).ToList();
                var files    = db.esc_profilegamesFiles.Where(x => x.gameId == gId && x.accountId == aId).ToList();
                cVM = new CoachingVM()
                {
                    Title         = pGame.Title,
                    Description   = pGame.Description,
                    GameId        = gId,
                    AccountId     = aId,
                    ServiceTypeId = pGame.serviceTypeId
                };
                cVM.Faqs     = faqs;
                cVM.Pricings = pricings;
                cVM.Files    = files;

                return(View(cVM));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public ActionResult Create()
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login", "Auth"));
            }
            try
            {
                var games = db.esc_games.ToList();
                //var games = new SelectList(db.esc_games.ToList(), "Id", "Game");
                var serviceTypes = new SelectList(db.esc_serviceTypes.ToList(), "Id", "Name");

                ViewBag.DBGames            = games;
                ViewData["DBServiceTypes"] = serviceTypes;
                ViewBag.DBHours            = PriceHourModel.GetPriceHours().ToList();
                return(View());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public ActionResult Edit(CoachingVM coaching, HttpPostedFileBase file)
        {
            try
            {
                if (coaching.AccountId <= 0 && coaching.GameId <= 0)
                {
                    ViewBag.Error = "Invalid model value.";
                    return(View(coaching));
                }
                var games        = db.esc_games.ToList();
                var serviceTypes = new SelectList(db.esc_serviceTypes.ToList(), "Id", "Name");
                ViewBag.DBGames            = games;
                ViewData["DBServiceTypes"] = serviceTypes;
                ViewBag.DBHours            = PriceHourModel.GetPriceHours().ToList();
                var user  = GetCurrentUser();
                var pGame = db.esc_profilegames.Where(x => x.gameId == coaching.GameId && x.accountId == user.Id).FirstOrDefault();
                if (pGame == null)
                {
                    ViewBag.Error = "No game found for your reference.";
                    return(View(coaching));
                }
                pGame.serviceTypeId = coaching.ServiceTypeId;
                pGame.Title         = coaching.Title;
                pGame.Description   = coaching.Description;

                var faqs = db.esc_faq.Where(x => x.gameId == coaching.GameId && x.accountId == user.Id).ToList();
                foreach (var item in faqs)
                {
                    db.esc_faq.Remove(item);
                }
                foreach (var item in coaching.Faqs)
                {
                    var faq = new esc_faq()
                    {
                        accountId   = user.Id,
                        gameId      = coaching.GameId,
                        Description = item.Description,
                        Title       = item.Title
                    };
                    if (faq.Title != null && faq.Description != null)
                    {
                        db.esc_faq.Add(faq);
                    }
                }

                var pricings = db.esc_profilegamesPricing.Where(x => x.gameId == coaching.GameId && x.accountId == user.Id).ToList();
                foreach (var item in pricings)
                {
                    db.esc_profilegamesPricing.Remove(item);
                }
                foreach (var item in coaching.Pricings)
                {
                    var price = new esc_profilegamesPricing()
                    {
                        accountId = user.Id,
                        gameId    = coaching.GameId,
                        Hours     = item.Hours,
                        Price     = item.Price
                    };
                    if (price.Hours > 0 && price.Price > 0)
                    {
                        db.esc_profilegamesPricing.Add(price);
                    }
                }
                //var files = db.esc_profilegamesFiles.Where(x => x.gameId == coaching.GameId && x.accountId == user.Id).ToList();
                //HttpPostedFileBase images1 = Request.Files["ImageData1"];
                //HttpPostedFileBase images2 = Request.Files["ImageData2"];
                //HttpPostedFileBase images3 = Request.Files["ImageData3"];
                //HttpPostedFileBase videos = Request.Files["VideoData"];
                //List<PathImageAndVideo> listOfNames = new List<PathImageAndVideo>();

                db.SaveChanges();
                ViewBag.Success = "Coaching update successfully.";
                return(View(coaching));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
示例#4
0
        public ActionResult Create(CoachingVM model)
        {
            try
            {
                var games        = db.esc_games.ToList();
                var serviceTypes = new SelectList(db.esc_serviceTypes.ToList(), "Id", "Name");
                ViewBag.DBGames            = games;
                ViewData["DBServiceTypes"] = serviceTypes;
                ViewBag.DBHours            = PriceHourModel.GetPriceHours().ToList();
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var user  = GetCurrentUser();
                var pGame = db.esc_profilegames.Where(x => x.gameId == model.GameId && x.accountId == user.Id).FirstOrDefault();
                if (pGame != null)
                {
                    ViewBag.Error = "You are already coaching in this game! Please edit or delete that coaching and try again.";
                    return(View(model));
                }
                var profileGame = new esc_profilegames()
                {
                    gameId        = model.GameId,
                    accountId     = user.Id,
                    Title         = model.Title,
                    Description   = model.Description,
                    serviceTypeId = model.ServiceTypeId
                };
                db.esc_profilegames.Add(profileGame);

                if (model.Pricings != null)
                {
                    foreach (var item in model.Pricings)
                    {
                        var price = new esc_profilegamesPricing()
                        {
                            accountId = user.Id,
                            gameId    = model.GameId,
                            Hours     = item.Hours,
                            Price     = item.Price
                        };
                        if (price.Hours > 0 && price.Price > 0)
                        {
                            db.esc_profilegamesPricing.Add(price);
                        }
                    }
                }

                if (model.Faqs != null)
                {
                    foreach (var item in model.Faqs)
                    {
                        var faq = new esc_faq()
                        {
                            accountId   = user.Id,
                            gameId      = model.GameId,
                            Description = item.Description,
                            Title       = item.Title
                        };
                        if (faq.Title != null && faq.Description != null)
                        {
                            db.esc_faq.Add(faq);
                        }
                    }
                }



                HttpPostedFileBase       images1     = Request.Files["ImageData1"];
                HttpPostedFileBase       images2     = Request.Files["ImageData2"];
                HttpPostedFileBase       images3     = Request.Files["ImageData3"];
                HttpPostedFileBase       videos      = Request.Files["VideoData"];
                List <PathImageAndVideo> listOfNames = new List <PathImageAndVideo>();

                if (images1 != null && images1.ContentLength > 0)
                {
                    string imgName = Path.GetFileNameWithoutExtension(images1.FileName);
                    imgName  = user.Id + "" + model.GameId + "" + Guid.NewGuid() + "_" + imgName;
                    imgName += Path.GetExtension(images1.FileName);
                    string _path = Path.Combine(Server.MapPath("~/CoachingImages"), imgName);
                    listOfNames.Add(new PathImageAndVideo()
                    {
                        Name = imgName, FileType = 1, FilePath = "CoachingImages"
                    });
                    images1.SaveAs(_path);
                }
                if (images2.ContentLength > 0)
                {
                    string imgName = Path.GetFileNameWithoutExtension(images2.FileName);
                    imgName  = user.Id + "" + model.GameId + "" + Guid.NewGuid() + "_" + imgName;
                    imgName += Path.GetExtension(images2.FileName);
                    string _path = Path.Combine(Server.MapPath("~/CoachingImages"), imgName);
                    listOfNames.Add(new PathImageAndVideo()
                    {
                        Name = imgName, FileType = 1, FilePath = "CoachingImages"
                    });
                    images2.SaveAs(_path);
                }
                if (images3.ContentLength > 0)
                {
                    string imgName = Path.GetFileNameWithoutExtension(images3.FileName);
                    imgName = user.Id + "" + model.GameId + "" + Guid.NewGuid() + "_" + imgName;
                    //imgName = user.Id + "" + model.GameId + "" + DateTime.UtcNow.ToString("dd-MM-yyyy") + "_" + imgName;
                    imgName += Path.GetExtension(images3.FileName);
                    string _path = Path.Combine(Server.MapPath("~/CoachingImages"), imgName);
                    listOfNames.Add(new PathImageAndVideo()
                    {
                        Name = imgName, FileType = 1, FilePath = "CoachingImages"
                    });
                    images3.SaveAs(_path);
                }
                if (videos.ContentLength > 0)
                {
                    string videoName = Path.GetFileNameWithoutExtension(videos.FileName);
                    //videoName = user.Id + "" + model.GameId + "" + DateTime.UtcNow.ToString("dd-MM-yyyy") + "_" + videoName;
                    videoName  = user.Id + "" + model.GameId + "" + Guid.NewGuid() + "_" + videoName;
                    videoName += Path.GetExtension(videos.FileName);
                    string _path = Path.Combine(Server.MapPath("~/CoachingVideos"), videoName);
                    listOfNames.Add(new PathImageAndVideo()
                    {
                        Name = videoName, FileType = 2, FilePath = "CoachingVideos"
                    });
                    videos.SaveAs(_path);
                }

                // Save all type of file paths into database
                foreach (var item in listOfNames)
                {
                    var file = new esc_profilegamesFiles
                    {
                        accountId = user.Id,
                        gameId    = model.GameId,
                        FileName  = item.Name,
                        FileType  = item.FileType,
                        FilePath  = item.FilePath
                    };
                    db.esc_profilegamesFiles.Add(file);
                }

                // Commit all database changes.
                db.SaveChanges();
                ViewBag.Success = "Coaching have been saved successfully!";
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return(View(model));
            }
        }