Ejemplo n.º 1
0
        private void GenerateSchedule(List <Staff> staffs, List <int> scheduleListWithRules)
        {
            int currentItemIndex = 0;

            try
            {
                DateTime ShiftDate = FirstWorkingDayDate;
                foreach (var item in scheduleListWithRules)
                {
                    if (staffs[item] != null)
                    {
                        Schedule sch = new Schedule();
                        sch.StaffId = staffs[item].Id; //item

                        if (currentItemIndex == 0 || currentItemIndex % 2 == 0)
                        {
                            sch.Shift = Shift.First;
                        }
                        else
                        {
                            sch.Shift = Shift.Second;
                        }

                        sch.Date = ShiftDate;
                        ActiveSchedule.Add(sch);
                        if (currentItemIndex > 0 && currentItemIndex % 2 != 0)
                        {
                            ShiftDate = ShiftDate.AddDays(1);
                        }
                    }
                    currentItemIndex++;
                }

                _scheduleRepo.AddRange(ActiveSchedule);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception occured while Generating Schedule");
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Add([FromForm] BookModel model)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Student", "Teacher" }))
                {
                    bool saved;
                    if (ModelState.IsValid)
                    {
                        string[]   tags     = model.Tags.Split(',');
                        List <Tag> bookTags = new List <Tag>();
                        foreach (var tag in tags)
                        {
                            Tag t = await _context.GetByNameAsync <Tag>(x => x.Name.ToLower() == tag.Trim().ToLower());

                            bookTags.Add(t);
                        }

                        PhotoUploadCloudinary upload = new PhotoUploadCloudinary(_cloudinaryConfig);
                        Photo photo = upload.Upload(model.Cover);

                        PdfUploadCloudinary pdfUpload = new PdfUploadCloudinary(_cloudinaryConfig);
                        File file = pdfUpload.Upload(model.Book);

                        Book item = new Book
                        {
                            Name            = model.Name,
                            AppIdentityUser = this.GetLoggedUser(_auth, _context),
                            Photo           = photo,
                            File            = file,
                            Author          = model.Author,
                            Language        = await _context.GetByIdAsync <Language>(x => x.Id == model.LanguageId),
                            Year            = model.Year,
                            Pages           = model.Pages,
                            Faculty         = await _context.GetByIdAsync <Faculty>(x => x.Id == model.FacultyId)
                        };

                        List <PostTag> tagPosts = new List <PostTag>();
                        foreach (var tag in bookTags)
                        {
                            tagPosts.Add(new PostTag()
                            {
                                Post = item, Tag = tag
                            });
                        }

                        item.PostTags = tagPosts;

                        await _context.Add(photo);

                        await _context.Add(item);

                        await _context.SaveAll();

                        var broadcast = new Notifier(_context, _auth);
                        await _context.AddRange(await broadcast.NewBook(item));

                        saved = await _context.SaveAll();

                        if (saved == true)
                        {
                            if (item.AppIdentityUser.UserType == "Student")
                            {
                                BookViewModel viewModel = new BookViewModel(item);
                                viewModel.GroupName = _context.GetUserGroup(item.AppIdentityUserId);
                                return(Ok(viewModel));
                            }
                            return(Ok(new BookViewModel(item)));
                        }
                    }
                    return(BadRequest("Model is not valid"));
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }