Example #1
0
        public async Task <IActionResult> Create([Bind("ProjectId,Name,Start,Deadline,Budget,Deposit,Status")] Projects projects)
        {
            if (ModelState.IsValid)
            {
                _context.Add(projects);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(projects));
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,FirstName,LastName,Birthday,PhoneNumber,Position,Salary,Experiance,BeginningOfWork,Image,Description")] Employees employees)
        {
            if (ModelState.IsValid)
            {
                employees.CalculateMonthPaymentFrom = employees.BeginningOfWork;
                employees.Vacation = 0;
                employees.Overtime = 0;
                UploadPhoto(employees);
                _context.Add(employees);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employees));
        }
        /// <summary>
        /// Add a new customer.
        /// </summary>
        public void Add(Library.Model.Customer model)
        {
            if (model.CustomerId != 0)
            {
                s_logger.Warn($"Customer to be added has an ID ({model.CustomerId}) already: ignoring.");
            }

            s_logger.Info($"Adding Customer");

            // ID left at default 0
            Customer entity = new Customer
            {
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                Address    = model.Address,
                City       = model.City,
                State      = model.State,
                Country    = model.Country,
                PostalCode = model.PostalCode,
                Phone      = model.Phone,
                Email      = model.Email
            };

            _customerContext.Add(entity);
        }
        /// <summary>
        /// Add and save new orders to store locations for customers.
        /// </summary>
        public void Add(Library.Model.Order model)
        {
            if (model.OrderId != 0)
            {
                s_logger.Warn($"Order to be added has an ID ({model.OrderId}) already: ignoring.");
                return;
            }
            foreach (Library.Model.OrderLine ol in model.OrderLines)
            {
                if (ol.OrderLineId != 0)
                {
                    s_logger.Warn($"OrderLine to be added has an ID ({ol.OrderLineId}) already: ignoring.");
                    return;
                }
            }

            s_logger.Info($"Adding Order");

            var products = _orderContext.Products
                           .AsNoTracking();

            // ID left at default 0
            Order entity = new Order
            {
                CustomerId = model.CustomerId,
                LocationId = model.LocationId,
                OrderTime  = model.OrderTime,
                OrderTotal = 0.00M
            };

            _orderContext.Add(entity);

            foreach (Library.Model.OrderLine ol in model.OrderLines)
            {
                OrderLine entity2 = new OrderLine
                {
                    Order     = entity,
                    ProductId = ol.ProductId,
                    Quantity  = ol.Quantity,
                    LineTotal = ol.Quantity * products.First(p => p.ProductId == ol.ProductId).UnitPrice
                };
                entity.OrderTotal += entity2.LineTotal;
                _orderContext.Add(entity2);
            }
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Id,Author,NameChange,ProjLanguage,LanguageChange,DevTime,ChangeCount")] ReportJournal reportJournal)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reportJournal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reportJournal));
        }
        /// <summary>
        /// Add a new user.
        /// </summary>
        public void Add(Library.Model.User model)
        {
            if (model.UserId != 0)
            {
                s_logger.Warn($"Customer to be added has an ID ({model.UserId}) already: ignoring.");
            }

            s_logger.Info($"Adding Customer");

            // ID left at default 0
            User entity = new User
            {
                Username = model.Username,
                Password = model.Password
            };

            _userContext.Add(entity);
        }
Example #7
0
        public async Task <IActionResult> AddorEdit(int Id,
                                                    [Bind("Id,Name,Language,Info,StartDate,EndDate,ProjectDataId,ReportJournalId")]
                                                    ProjectViewModel project)
        {
            if (ModelState.IsValid)
            {
                if (project.Id == 0)
                {
                    var userId = _userManager.GetUserId(this.HttpContext.User);
                    project.ProjectUserId = userId;

                    var projects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var langTypes = projects.GroupBy(x => x.Language).ToList();

                    foreach (var c in allChartData)
                    {
                        if (userId == c.ChartUserId)
                        {
                            project.ProjectDataId = c.Id;

                            _context.Add(project);
                            _context.Update(c);
                            c.DataForProjects.Add(project);

                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }

                        else
                        {
                            project.ProjectUserId = userId;

                            var newChartData = new ChartData
                            {
                                ChartUserId = userId
                            };

                            _context.Add(project);
                            _context.Add(newChartData);
                            project.ProjectDataId = newChartData.Id;
                            newChartData.DataForProjects.Add(project);
                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }
                    }
                }

                else
                {
                    var userId          = _userManager.GetUserId(this.HttpContext.User);
                    var currentProjects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allCurrentChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    foreach (var c in allCurrentChartData)
                    {
                        _context.Update(project);
                        _context.Update(c);
                        await _context.SaveChangesAsync();

                        TempData["Message"] = "Project Updated!";
                        return(View(project));
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            else
            {
                TempData["Message"] = "Please try again.";
                return(RedirectToAction(nameof(AddorEdit)));
            }
        }