예제 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await Task.Run(() =>
            {
                Company.company_create_date = DateTime.Now;
            });

            db.Add(Company);
            await db.CommitAsync();

            await Task.Run(() =>
            {
                user.CompanyID = Company.companyId;
            });

            if (Imgfile != null)
            {
                CompanyPicInfo = CompanyPicInfo == null ? new CompanyPicture() : CompanyPicInfo;
                //Upload to file system
                string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName);
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                //Update database
                await Task.Run(() =>
                {
                    CompanyPicInfo.Path      = uniqueFileName;
                    CompanyPicInfo.imageType = ImageType.Icon;
                    CompanyPicInfo.CompanyId = Company.companyId;
                });

                picdb.AddIcon(CompanyPicInfo);
                await picdb.CommitAsync();

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Imgfile.CopyToAsync(fileStream);
                }
            }

            await userManager.UpdateAsync(user);

            await signInManager.RefreshSignInAsync(user);

            TempData["CompanyStatus"] = "Your company profile has been created!";
            return(RedirectToPage("./Index"));
        }
예제 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //PlatformOfGame
            if (newGamePlatform != null && newGamePlatform.PlatformId != 0)
            {
                newGamePlatform.GameId = Game.GameId;
                gamePlatformdb.Add(newGamePlatform);
                await gamePlatformdb.CommitAsync();

                return(RedirectToPage("./EditGame", new { id = Game.GameId }));
            }
            else if (delGamePlatform != null && delGamePlatform.PlatformId != 0)
            {
                delGamePlatform = gamePlatformdb.GetById(delGamePlatform.GameId, delGamePlatform.PlatformId);
                if (delGamePlatform == null)
                {
                    return(Page());
                }
                gamePlatformdb.Delete(delGamePlatform);
                await gamePlatformdb.CommitAsync();

                return(RedirectToPage("./EditGame", new { id = delGamePlatform.GameId }));
            }

            //Game
            Game.HtmlText = HttpUtility.HtmlEncode(Game.HtmlText);
            Game.Price    = Math.Round(Game.Price, 2, MidpointRounding.ToEven);

            db.Update(Game);
            await db.CommitAsync();

            //Image uploading
            if (Imgfile != null)
            {
                GamePicInfo = GamePicInfo == null ? new GamePicture() : GamePicInfo;
                //Upload to file system
                string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName);
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                //Update database
                GamePicInfo.Path      = uniqueFileName;
                GamePicInfo.imageType = ImageType.Icon;
                GamePicInfo.GameId    = Game.GameId;
                picdb.AddIcon(GamePicInfo);
                await picdb.CommitAsync();

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Imgfile.CopyToAsync(fileStream);
                }
            }
            //Info images update
            if (infoImg != null)
            {
                //Remove old info image
                var oldinfo = picdb.GetById(Game.GameId, ImageType.Info);
                foreach (var r in oldinfo)
                {
                    picdb.Delete(r);
                }
                await picdb.CommitAsync();

                foreach (var r in infoImg)
                {
                    await Task.Run(async() =>
                    {
                        string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                        string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + r.FileName);
                        string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                        var infoImage         = new GamePicture
                        {
                            GameId    = Game.GameId,
                            imageType = ImageType.Info,
                            Path      = uniqueFileName
                        };
                        //update database
                        picdb.Add(infoImage);
                        await picdb.CommitAsync();
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await r.CopyToAsync(fileStream);
                        }
                    });
                }
            }
            TempData["CompanyStatus"] = "Your game has been updated!";

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                PlatformList = new SelectList(platformdb.GetAllByName(""), "PlatformId", "Platform_name");
                return(Page());
            }

            var user = await userManager.GetUserAsync(User);

            await Task.Run(() =>
            {
                var companyId    = user.CompanyID;
                Game.CompanyID   = (int)companyId;
                Game.HtmlText    = HttpUtility.HtmlEncode(Game.HtmlText);
                Game.Price       = Math.Round(Game.Price, 2, MidpointRounding.ToEven);
                Game.ReleaseDate = DateTime.Now;
            });

            db.Add(Game);
            await db.CommitAsync();

            //PlatformOfGame
            newGamePlatform.GameId = Game.GameId;
            gamePlatformdb.Add(newGamePlatform);
            await gamePlatformdb.CommitAsync();

            //Image uploading
            if (Imgfile != null)
            {
                GamePicInfo = GamePicInfo == null ? new GamePicture() : GamePicInfo;
                //Upload to file system
                string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName);
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                await Task.Run(() =>
                {
                    GamePicInfo.Path      = uniqueFileName;
                    GamePicInfo.imageType = ImageType.Icon;
                    GamePicInfo.GameId    = Game.GameId;
                });

                //Update database
                picdb.AddIcon(GamePicInfo);
                await picdb.CommitAsync();

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Imgfile.CopyToAsync(fileStream);
                }
            }
            //Info images update
            if (infoImg != null)
            {
                //Remove old info image
                var oldinfo = picdb.GetById(Game.GameId, ImageType.Info);
                foreach (var r in oldinfo)
                {
                    picdb.Delete(r);
                    await picdb.CommitAsync();
                }
                foreach (var r in infoImg)
                {
                    await Task.Run(async() =>
                    {
                        string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                        string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + r.FileName);
                        string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                        var infoImage         = new GamePicture
                        {
                            GameId    = Game.GameId,
                            imageType = ImageType.Info,
                            Path      = uniqueFileName
                        };
                        //update database
                        picdb.Add(infoImage);
                        await picdb.CommitAsync();
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await r.CopyToAsync(fileStream);
                        }
                    });
                }
            }
            return(RedirectToPage("../g/Index"));
        }
예제 #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                NewsLetterModel Model = new NewsLetterModel();

                Model.FirstContent  = FirstContent.Text;
                Model.SecondContent = SecondContent.Text;
                Model.ThirldContent = ThirdContent.Text;

                string SelectedIds = GetHiddenValue();

                if (Imgfile.PostedFile != null && Imgfile.PostedFile.FileName != "")
                {
                    var    fileExt  = Path.GetExtension(Imgfile.FileName);
                    string fileName = Guid.NewGuid() + fileExt;
                    var    subPath  = Server.MapPath("~/uploadfiles");

                    //Check SubPath Exist or Not
                    if (!Directory.Exists(subPath))
                    {
                        Directory.CreateDirectory(subPath);
                    }
                    //End : Check SubPath Exist or Not

                    var path = Path.Combine(subPath, fileName);
                    Imgfile.SaveAs(path);
                    var URL = ConfigurationManager.AppSettings["LocalURL"].ToString();
                    Model.PropertyPhoto = URL + "/uploadfiles/" + fileName;
                }
                //else
                //{
                //    Model.PropertyPhoto = "../NewsLetterImages/img1F.jpg";
                //}

                if (Logofile.PostedFile != null && Logofile.PostedFile.FileName != "")
                {
                    //Save the photo in Folder
                    var    fileExt  = Path.GetExtension(Logofile.FileName);
                    string fileName = Guid.NewGuid() + fileExt;
                    var    subPath  = Server.MapPath("~/uploadfiles");

                    //Check SubPath Exist or Not
                    if (!Directory.Exists(subPath))
                    {
                        Directory.CreateDirectory(subPath);
                    }
                    //End : Check SubPath Exist or Not

                    var path = Path.Combine(subPath, fileName);
                    Logofile.SaveAs(path);
                    var URL = ConfigurationManager.AppSettings["LocalURL"].ToString();
                    Model.Logopath = URL + "/uploadfiles/" + fileName;
                }
                //else
                //{
                //    Model.Logopath = "../images/MyLogodd%20-%20Copy.png";
                //}
                Model.AdminPhoto = "../images/client_img.jpg";



                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                DataTable      dt  = new DataTable();
                string         str = "select EmailId from [AdminClient] where ID in(" + SelectedIds + ")";
                SqlDataAdapter adp = new SqlDataAdapter(str, conn);
                adp.Fill(dt);

                foreach (DataRow row in dt.Rows)
                {
                    var Email = row["EmailId"].ToString();
                    Model.Email = Email;
                    SendNewsLetter(Model);
                }

                // }


                Response.Redirect("~/Admin/NewsLetter.aspx", false);
            }

            catch (Exception ex)
            {
                //throw ex;
            }
        }