public CompanyPicture AddIcon(CompanyPicture newPicture)
        {
            var old = this.GetIconById(newPicture.CompanyId);

            db.Add(newPicture);
            if (old != null)
            {
                this.Delete(old);
            }
            return(newPicture);
        }
Ejemplo n.º 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()
        {
            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"));
        }
 public void Delete(CompanyPicture deletePicture)
 {
     db.Remove(deletePicture);
 }
 public CompanyPicture Add(CompanyPicture newPicture)
 {
     db.Add(newPicture);
     return(newPicture);
 }