public async Task <IActionResult> Create(StaffViewModel model)
        {
            model.SelectList = db.Positions.Select(p => p.Name).ToList();

            var position = db.Positions.FirstOrDefault(g => g.Name == model.PositionName);

            if (position == null)
            {
                ModelState.AddModelError(string.Empty, "Please select position from list.");
                return(View(model));
            }

            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.PositionId = position.PositionId;

                await db.Staff.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Create(AppealsViewModel model)
        {
            model.SelectList = db.Shows.ToList();

            var show = db.Shows.FirstOrDefault(s => s.Name == model.ShowName);

            if (show == null)
            {
                ModelState.AddModelError(string.Empty, "Please select show from list.");
                return(View(model));
            }

            model.Entity.Show = new Show {
                Name = model.ShowName
            };
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.Show   = null;
                model.Entity.ShowId = show.ShowId;

                await db.Appeals.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Create([Bind("Id,PositionName")] Position position)
        {
            if (ModelState.IsValid)
            {
                _context.Add(position);
                await _context.SaveChangesAsync();

                _cache.Clean();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,NameOfType,Note")] GroupType groupType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(groupType);
                await _context.SaveChangesAsync();

                _cache.Clean();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(groupType));
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("Id,FullName,Adress,Phone,PositionId,Info,Reward")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                _cache.Clean();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PositionId"] = new SelectList(_context.Positions, "Id", "Id", staff.PositionId);
            return(View(staff));
        }
        public async Task <IActionResult> Create(CostsViewModel costsViewModel)
        {
            if (ModelState.IsValid)
            {
                await context.Costs.AddAsync(costsViewModel.Cost);

                await context.SaveChangesAsync();

                cache.Clean();
                return(RedirectToAction("Index", "Costs"));
            }

            return(View(costsViewModel));
        }
Exemple #7
0
        public async Task <IActionResult> Create(StaffViewModel StaffViewModel)
        {
            if (ModelState.IsValid)
            {
                await context.Staff.AddAsync(StaffViewModel.Staff);

                await context.SaveChangesAsync();

                cache.Clean();
                return(RedirectToAction("Index", "Staff"));
            }

            return(View(StaffViewModel));
        }
Exemple #8
0
        public async Task <IActionResult> Create([Bind("Id,GroupName,StaffId,CountOfChildren,YearOfCreation,TypeId")] Group @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                _cache.Clean();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Id", @group.StaffId);
            ViewData["TypeId"]  = new SelectList(_context.GroupTypes, "Id", "Id", @group.TypeId);
            return(View(@group));
        }
        public async Task <IActionResult> Create([Bind("Id,FullName,BirthDate,Gender,ParentId,Adress,GroupId,Note,OtherGroup")] Child child)
        {
            if (ModelState.IsValid)
            {
                _context.Add(child);
                await _context.SaveChangesAsync();

                _cache.Clean();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupId"]  = new SelectList(_context.Groups, "Id", "Id", child.GroupId);
            ViewData["ParentId"] = new SelectList(_context.Parents, "Id", "Id", child.ParentId);
            return(View(child));
        }
        public async Task <IActionResult> Create(GsmViewModel gsmViewModel)
        {
            if (ModelState.IsValid)
            {
                await context.Gsm.AddAsync(gsmViewModel.Gsm);

                await context.SaveChangesAsync();

                cache.Clean();
                return(RedirectToAction("Index", "Gsm"));
            }

            return(View(gsmViewModel));
        }
        public async Task <IActionResult> Create(CarMarkViewModel model)
        {
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                await db.CarMarks.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

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

            return(View(model));
        }
        public async Task <IActionResult> Create(TimetablesViewModel model)
        {
            model.ShowsSelectList = await db.Shows.Select(s => s.Name).ToListAsync();

            model.StaffSelectList = await db.Staff.Select(s => s.FullName).ToListAsync();

            var show = db.Shows.FirstOrDefault(s => s.Name == model.ShowName);

            if (show == null)
            {
                ModelState.AddModelError(string.Empty, "Please select show from list.");
                return(View(model));
            }

            var staff = db.Staff.FirstOrDefault(s => s.FullName == model.StaffName);

            if (staff == null)
            {
                ModelState.AddModelError(string.Empty, "Please select staff from list.");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                if (model.Entity.Year > show.ReleaseDate.Year ||
                    (model.Entity.Year == show.ReleaseDate.Year && model.Entity.Month >= show.ReleaseDate.Month))
                {
                    model.Entity.ShowId  = show.ShowId;
                    model.Entity.EndTime = model.Entity.StartTime + show.Duration;
                    model.Entity.StaffId = staff.StaffId;

                    await db.Timetables.AddAsync(model.Entity);

                    await db.SaveChangesAsync();

                    cache.Clean();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, $"Mark year(month) must be more then release date ({show.ReleaseDate.ToString("d")})");
                }
            }

            return(View(model));
        }
Exemple #13
0
        public async Task <IActionResult> Create(CarModelViewModel model)
        {
            model.SelectList = db.CarMarks.ToList();
            var carMark = db.CarMarks.FirstOrDefault(g => g.Name == model.CarMarkName);

            if (carMark == null)
            {
                ModelState.AddModelError(string.Empty, "Please select carMark from list.");
                return(View(model));
            }
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.CarMarkId = carMark.CarMarkId;
                await db.CarModels.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

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

            return(View(model));
        }