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() })); }