public JsonResult AddCheckInRecords(CheckInRecord addCheckIn, List <string> Barcodes)
        {
            var           success = true;
            StringBuilder message = new StringBuilder(string.Empty);

            if (addCheckIn.IssueDate == default(DateTime))
            {
                foreach (var item in Barcodes)
                {
                    if (!bookRepository.IsBarcodeValid(item))
                    {
                        message.AppendLine($"Book with barcode:{item} doesn't exist.");
                        message.AppendLine();
                    }
                    else if (!checkInRepository.IsCheckInValid(addCheckIn, item))
                    {
                        message.AppendLine($"Book with barcode:{item} is already checked in or never issued.");
                        message.AppendLine();
                    }
                    else
                    {
                        var checkIn = checkInRepository.GetCheckInRecord(item);
                        checkIn.CheckInDate = addCheckIn.CheckInDate;
                        checkInRepository.Update <CheckInRecord>("CheckInRecords", checkIn);
                    }
                }
            }
            else
            {
                addCheckIn.Fairy_Id = addCheckIn.Fairy.Id;

                foreach (var item in Barcodes)
                {
                    if (!bookRepository.IsBarcodeValid(item))
                    {
                        message.AppendLine($"Book with barcode:{item} doesn't exist.");
                        message.AppendLine();
                    }
                    else if (!checkInRepository.IsIssueValid(addCheckIn, item))
                    {
                        message.AppendLine($"Book with barcode:{item} is not checked in. So, unable to issue.");
                        message.AppendLine();
                    }
                    else
                    {
                        addCheckIn.Book_Id = bookRepository.GetBookId(item);
                        checkInRepository.Create <CheckInRecord>("CheckInRecords", addCheckIn);
                    }
                }
            }

            return(Json(new { Success = success, Message = message.ToString() }));
        }
示例#2
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         if (CheckIn.Id > 0)
         {
             CheckIn = checkinRepository.Update(CheckIn);
         }
         else
         {
             CheckIn = checkinRepository.Add(CheckIn);
         }
         return(RedirectToPage("AddConfirmed"));
     }
     return(Page());
 }
示例#3
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (CheckIn.Id > 0)
                {
                    CheckIn = checkinRepository.Update(CheckIn);
                    if (CheckIn.Status == Status.OnSiteWait)
                    {
                        Task t = Task.Run(async() =>
                        {
                            //_mailSender.Send(email);
                            var body = $@"{CheckIn.Name}, please make your way to the Barber Shop.";

                            using (var smtp = new SmtpClient())
                            {
                                var credential = new NetworkCredential
                                {
                                    UserName = "******",
                                    Password = "******"
                                };
                                smtp.Credentials = credential;
                                smtp.Host        = "smtp.gmail.com";
                                smtp.Port        = 587;
                                smtp.EnableSsl   = true;
                                var msg          = new MailMessage();
                                msg.Body         = body;
                                msg.Subject      = "Please make your way to the baber shop";
                                msg.From         = new MailAddress("*****@*****.**");
                                msg.To.Add(CheckIn.PhoneNumber);
                                await smtp.SendMailAsync(msg);
                            }
                        });
                        t.Wait();
                        return(RedirectToPage("Index"));
                    }
                }
                else
                {
                    CheckIn = checkinRepository.Add(CheckIn);
                }

                return(RedirectToPage("Index"));
            }
            return(Page());
        }