예제 #1
0
        public async Task CreateRawMaterial(RawMaterialViewModel viewModel)
        {
            var rawMaterial = _mapper.Map <RawMaterial>(viewModel);

            _context.RawMaterials.Add(rawMaterial);
            await _context.SaveChangesAsync();
        }
예제 #2
0
        public async Task CreatePurchase(PurchaseViewModel viewModel)
        {
            var purchase = _mapper.Map <Purchase>(viewModel);

            _context.Purchases.Add(purchase);
            await _context.SaveChangesAsync();
        }
예제 #3
0
        public async Task CreateOrder(OrderViewModel viewModel)
        {
            var order = _mapper.Map <Order>(viewModel);

            _context.Add(order);
            await _context.SaveChangesAsync();
        }
예제 #4
0
        public async Task CreateDiscount(DiscountViewModel viewModel)
        {
            var discount = _mapper.Map <Discount>(viewModel);

            _context.Add(discount);
            await _context.SaveChangesAsync();
        }
예제 #5
0
        public async Task <Leave> CreateLeave(
            LeaveViewModel viewModel, ClaimsPrincipal user, HttpRequest request)
        {
            foreach (var file in request.Form.Files)
            {
                var memoryStream = new MemoryStream();
                file.CopyTo(memoryStream);
                viewModel.File     = memoryStream.ToArray();
                viewModel.FileName = file.FileName;
            }

            var leave    = _mapper.Map <Leave>(viewModel);
            var employee = await _context.Employees
                           .FirstOrDefaultAsync(e => e.UserId ==
                                                user.FindFirstValue(ClaimTypes.NameIdentifier)); //this is how we get the user Id

            leave.EmployeeId = employee.Id;

            leave.LeaveHistories.Add(new LeaveHistory
            {
                ApplicationDate = DateTime.Now,
                EmployeeId      = employee.Id
            });

            _context.Add(leave);
            await _context.SaveChangesAsync();

            return(leave);
        }
예제 #6
0
        public async Task CreateDepartment(DepartmentViewModel viewModel)
        {
            var department = _mapper.Map <Department>(viewModel);

            _context.Add(department);
            await _context.SaveChangesAsync();
        }
예제 #7
0
        public async Task CreateOfferItem(OfferItemViewModel viewModel)
        {
            var offerItem = _mapper.Map <OfferItem>(viewModel);

            _context.Add(offerItem);
            await _context.SaveChangesAsync();
        }
예제 #8
0
        public async Task CreateShelf(ShelfViewModel viewModel)
        {
            var shelf = _mapper.Map <Shelf>(viewModel);

            _context.Shelves.Add(shelf);
            await _context.SaveChangesAsync();
        }
예제 #9
0
        public async Task CreateCandidateInfo(CandidateViewModel viewModel, int id)
        {
            var address = _mapper.Map <Address>(viewModel.Address);

            address.CandidateId = id;
            await _context.Addresses.AddAsync(address);

            var phone = _mapper.Map <Phone>(viewModel.Phone);

            phone.CandidateId = id;
            await _context.Phones.AddAsync(phone);

            var email = _mapper.Map <Email>(viewModel.Email);

            email.CandidateId = id;
            await _context.Emails.AddAsync(email);

            var candidatePosition = new CandidatePosition();

            candidatePosition.PositionId  = viewModel.PositionId;
            candidatePosition.CandidateId = id;
            await _context.CandidatePositions.AddAsync(candidatePosition);

            await _context.SaveChangesAsync();
        }
예제 #10
0
        public async Task CreateInterview(InterviewViewModel viewModel)
        {
            var interview = _mapper.Map <Interview>(viewModel);

            _context.Add(interview);
            await _context.SaveChangesAsync();
        }
예제 #11
0
        public async Task CreateDiscountLevel(DiscountLevelViewModel viewModel)
        {
            viewModel.DiscountPercentage = viewModel.DiscountPercentage / 100;
            var discountLevel = _mapper.Map <DiscountLevel>(viewModel);
            await _context.AddAsync(discountLevel);

            await _context.SaveChangesAsync();
        }
예제 #12
0
        public async Task CreatePosition(PositionViewModel viewModel)
        {
            var position = _mapper.Map <Position>(viewModel);

            await _context.AddAsync(position);

            await _context.SaveChangesAsync();
        }
예제 #13
0
        public async Task <Sector> CreateSector(SectorViewModel viewModel)
        {
            var sector = _mapper.Map <Sector>(viewModel);
            await _context.Sectors.AddAsync(sector);

            await _context.SaveChangesAsync();

            return(sector);
        }
예제 #14
0
        public async Task <StorageUnit> CreateStorageUnit(StorageUnitViewModel viewModel)
        {
            var storageUnit = _mapper.Map <StorageUnit>(viewModel);

            _context.StorageUnits.Add(storageUnit);

            await _context.SaveChangesAsync();

            return(storageUnit);
        }
예제 #15
0
        public async Task <Meeting> CreateMeeting(Meeting meeting)
        {
            var createMeeting = _context.Add(meeting);

            await _context.SaveChangesAsync();

            return(meeting);
        }
예제 #16
0
        public async Task <Employee> CreateEmployee(EmployeeViewModel viewModel)
        {
            var user = new IdentityUser
            {
                UserName = viewModel.UserName,
                Email    = viewModel.Email
            };

            await _userManager.CreateAsync(user, viewModel.Password);

            var employee = _mapper.Map <Employee>(viewModel);

            employee.UserId = user.Id;
            _context.Add(employee);
            await _context.SaveChangesAsync();

            return(employee);
        }
예제 #17
0
        public async Task CreateCustomerInfo(CustomerViewModel viewModel, int id)
        {
            var address = _mapper.Map <Address>(viewModel.Address);

            address.CustomerId = id;
            await _context.Addresses.AddAsync(address);

            var phone = _mapper.Map <Phone>(viewModel.Phone);

            phone.CustomerId = id;
            await _context.Phones.AddAsync(phone);

            var email = _mapper.Map <Email>(viewModel.Email);

            email.CustomerId = id;
            await _context.Emails.AddAsync(email);

            await _context.SaveChangesAsync();
        }
예제 #18
0
        public async Task CreateSupplier(SupplierViewModel viewModel)
        {
            var supplier = _mapper.Map <Supplier>(viewModel);

            _context.Add(supplier);
            await _context.SaveChangesAsync();

            await CreateSupplierEmail(viewModel, supplier.Id);
            await CreateSupplierPhone(viewModel, supplier.Id);
            await CreateSupplierAddress(viewModel, supplier.Id);
        }
예제 #19
0
        public async Task <Warehouse> CreateWarehouse(WarehouseViewModel viewModel)
        {
            var warehouse = _mapper.Map <Warehouse>(viewModel);
            await _context.Warehouses.AddAsync(warehouse);

            await _context.SaveChangesAsync();

            await CreateWarehouseAddress(viewModel, warehouse.Id);

            await CreateWarehouseStorageUnits(viewModel, warehouse.Id);

            await CreateWarehousePhone(viewModel, warehouse.Id);

            await CreateWarehouseEmail(viewModel, warehouse.Id);

            return(warehouse);
        }
예제 #20
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser
                {
                    UserName = model.UserName,
                    Email    = model.Email,
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                var mail = new Email
                {
                    CustomerId = model.Id,
                    Mail       = model.Email,
                    MailType   = MailType.Personal
                };
                _context.Emails.Add(mail);

                var phone = new Phone
                {
                    CustomerId = model.Id,
                    Number     = model.Number,
                    PhoneType  = PhoneType.Personal
                };
                _context.Phones.Add(phone);

                var address = new Address
                {
                    CustomerId    = model.Id,
                    Location      = model.Location,
                    AddressNumber = model.AddressNumber,
                    Country       = model.Country,
                    PostCode      = model.PostCode
                };
                _context.Addresses.Add(address);

                var customer = new Customer
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    UserId    = user.Id,
                    Emails    = { mail },
                    Phones    = { phone },
                    Addresses = { address }
                };
                _context.Customers.Add(customer);

                await _context.SaveChangesAsync();



                if (result.Succeeded)
                {
                    MailMessage mailMessage = new MailMessage("*****@*****.**", user.Email);
                    mailMessage.Subject = "Welcome to Lozan Chocolates";
                    mailMessage.Body    = "Welcome to Lozan. Lozan was created by our lord and savior Takis Kamateros, founder and CEO of Lozan Chocolates. He was inspired " +
                                          "by his love for chocolate, and the joy it brought to people's lives. Lozan is a family business operating" +
                                          "in the Greek market since 2015. Over the course of those 6 years, through thick and thin, we have managed to " +
                                          "achieve significant recognition in the Greek market through the high quality of our products and the satisfaction of our customers. \n" +
                                          "By joining us, you took a step closer to a happier tomorrow, welcome to the family!";

                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);/* smtp.gmail.com ports: 25, 465, 587 */
                    smtpClient.Credentials = new System.Net.NetworkCredential()
                    {
                        UserName = "******",
                        Password = "******"
                    };

                    smtpClient.EnableSsl = true;

                    /*
                     * https://www.google.com/settings/security/lesssecureapps
                     */

                    smtpClient.Send(mailMessage);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
            }

            return(View(model));
        }