Esempio n. 1
0
        public async Task <IActionResult> Create(Agency agency)
        {
            Agency _agency = await db.Agencies.FirstOrDefaultAsync(a => a.Name == agency.Name);

            if (_agency == null)
            {
                IdentityResult result = await _roleManager.CreateAsync(new IdentityRole(agency.Name));

                db.Agencies.Add(agency);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(NotFound());
        }
Esempio n. 2
0
            public async Task <IActionResult> Register([FromBody] RegisterModel model)
            {
                var user = await GetUser(model.Email);

                if (user == null)
                {
                    user = new DAL.Models.User
                    {
                        Address = new DAL.Models.Address()
                    };
                    _context.Users.Add(user);
                    await Authenticate(model.Email);
                }

                user.Role            = DAL.Models.UserRole.Customer;
                user.Email           = model.Email;
                user.Password        = model.Password;
                user.Name            = model.Name;
                user.Surname         = model.Surname;
                user.DisplayAddress  = model.DisplayAddress;
                user.Address.Country = model.Address.Country;
                user.Address.City    = model.Address.City;
                user.Address.Street  = model.Address.Street;
                user.Address.House   = model.Address.House;
                user.Address.ZipCode = model.Address.ZipCode;

                await _context.SaveChangesAsync();

                var result = await GetUserProfile(model.Email);

                return(Ok(result));
            }
Esempio n. 3
0
        public async Task <ActionResult <User> > PostUser([FromBody] UserCred Cred)
        {
            var UserEx = _context.User.FirstOrDefault(u => u.UserName == Cred.UserName);

            if (UserEx != null)
            {
                return(Forbid());
            }
            else
            {
                User user = new User
                {
                    UserName = Cred.UserName,
                    Password = BCrypt.Net.BCrypt.HashPassword(Cred.UserPassword),
                    IsAdmin  = false
                };
                _context.User.Add(user);
                await _context.SaveChangesAsync();

                return(Ok(user));
            }
        }
Esempio n. 4
0
 public Task Insert(ProductDetail item)
 {
     this.db.ProductDetails.Add(item);
     return(db.SaveChangesAsync());
 }
Esempio n. 5
0
        public async Task <IActionResult> Execute(PartYearEventViewModel partYearEventViewModel)
        {
            if (partYearEventViewModel != null)
            {
                YearEvent yearEvent = await db.YearEvents.FirstOrDefaultAsync(y => y.Id == partYearEventViewModel.YearEventId);

                Agency agency = await db.Agencies.FirstOrDefaultAsync(ag => ag.Id == yearEvent.AgencyId);

                // путь к папке Files
                string path = Path.Combine(_appEnvironment.WebRootPath, "img");
                //string pathWWWRootNot = "\\img\\";

                if (!Directory.Exists(Path.Combine(path, agency.Name)))
                {
                    Directory.CreateDirectory(Path.Combine(path, agency.Name));
                }

                path = Path.Combine(path, agency.Name);
                string pathWWWRootNot = Path.Combine("img", agency.Name);

                if (!Directory.Exists(Path.Combine(path, partYearEventViewModel.DataYear)))
                {
                    Directory.CreateDirectory(Path.Combine(path, partYearEventViewModel.DataYear));
                }
                path           = Path.Combine(path, partYearEventViewModel.DataYear);
                pathWWWRootNot = Path.Combine(pathWWWRootNot, partYearEventViewModel.DataYear);

                if (!Directory.Exists(Path.Combine(path, partYearEventViewModel.NumberYearEvent.ToString())))
                {
                    Directory.CreateDirectory(Path.Combine(path, partYearEventViewModel.NumberYearEvent.ToString()));
                }

                path           = Path.Combine(path, partYearEventViewModel.NumberYearEvent.ToString());
                pathWWWRootNot = Path.Combine(pathWWWRootNot, partYearEventViewModel.NumberYearEvent.ToString());

                string fullFileNameImageFile;
                string fullFileNamePdfFile;

                string extensionImageFile = Path.GetExtension(partYearEventViewModel.ImageFile.FileName);
                string extensionPdfFile   = Path.GetExtension(partYearEventViewModel.PdfFile.FileName);

                string fileNameImageFile = $"ГП_image_{agency.Name}_{partYearEventViewModel.NumberYearEvent}_{DateTime.Now:dd-MM-yyyy-hh-mm-ss}{extensionImageFile}";
                string fileNamePdfFile   = $"ГП_pdf_{agency.Name}_{partYearEventViewModel.NumberYearEvent}_{DateTime.Now:dd-MM-yyyy-hh-mm-ss}{extensionPdfFile}";

                using (var fileStream = new FileStream(Path.Combine(path, fileNameImageFile), FileMode.Create))
                {
                    await partYearEventViewModel.ImageFile.CopyToAsync(fileStream);

                    await fileStream.FlushAsync();

                    fullFileNameImageFile = "\\" + Path.Combine(pathWWWRootNot, fileNameImageFile);
                }

                using (var fileStream = new FileStream(Path.Combine(path, fileNamePdfFile), FileMode.Create))
                {
                    await partYearEventViewModel.PdfFile.CopyToAsync(fileStream);

                    await fileStream.FlushAsync();

                    fullFileNamePdfFile = "\\" + Path.Combine(pathWWWRootNot, fileNamePdfFile);
                }

                PartYearEvent partYearEvent = new PartYearEvent()
                {
                    YearEventId     = partYearEventViewModel.YearEventId,
                    NumberYearEvent = partYearEventViewModel.NumberYearEvent,
                    Done            = partYearEventViewModel.Done,
                    PriceB          = partYearEventViewModel.PriceB,
                    PriceNotB       = partYearEventViewModel.PriceNotB,
                    DateTime        = DateTime.Now,
                    UserNameSent    = User.Identity.Name,
                    Img             = fullFileNameImageFile,
                    Pdf             = fullFileNamePdfFile
                };
                await db.PartYearEvents.AddAsync(partYearEvent);

                await db.SaveChangesAsync();
            }
            return(RedirectToAction("Index", new { userName = User.Identity.Name, dataYear = partYearEventViewModel.DataYear }));
        }
Esempio n. 6
0
        public async Task <IActionResult> DeleteUnit(int?id)
        {
            if (id != null)
            {
                Unit unit = await db.Units.FirstOrDefaultAsync(u => u.Id == id);

                if (unit != null)
                {
                    db.Units.Remove(unit);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(NotFound());
        }
Esempio n. 7
0
 public Task Insert(Region item)
 {
     this.db.Regions.Add(item);
     return(db.SaveChangesAsync());
 }