Exemplo n.º 1
0
        /// <summary>
        /// Delete user favourites
        /// </summary>
        /// <remarks>Removes a specific user favourite</remarks>
        /// <param name="id">id of Favourite to delete</param>
        /// <response code="200">OK</response>
        public virtual IActionResult UsersCurrentFavouritesIdDeletePostAsync(int id)
        {
            // get the current user id
            int?userId = GetCurrentUserId();

            if (userId != null)
            {
                bool exists = _context.UserFavourites.Where(x => x.User.Id == userId)
                              .Any(a => a.Id == id);

                if (exists)
                {
                    UserFavourite item = _context.UserFavourites.First(a => a.Id == id);

                    _context.UserFavourites.Remove(item);

                    // Save the changes
                    _context.SaveChanges();

                    return(new ObjectResult(new HetsResponse(item)));
                }

                // record not found
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create bulk time records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="201">Time Record created</response>
        public virtual IActionResult TimerecordsBulkPostAsync(TimeRecord[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (TimeRecord item in items)
            {
                AdjustRecord(item);

                bool exists = _context.TimeRecords.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.TimeRecords.Update(item);
                }
                else
                {
                    _context.TimeRecords.Add(item);
                }
            }

            // save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddToWaitlist(string ISBN)
        {
            //check if waitlist exists; if not: create a new one for the associated book

            var bookWaitlist = GetWaitlist(ISBN);

            if (bookWaitlist == null)
            {
                var new_waitlist = new Waitlist(ISBN);
                _context.Waitlists.Add(new_waitlist);
                _context.SaveChanges();
            }
            bookWaitlist = GetWaitlist(ISBN);

            var userEmail   = HttpContext.Items["Email"] as string;
            var userId      = _context.Users.FirstAsync(x => x.Email == userEmail).Id;
            var checkExists =
                _context.WaitingPeople.FirstOrDefault(
                    x => x.UserUserID == userId && x.WaitlistListID == bookWaitlist.ListID);

            if (checkExists == null)
            {
                var waitingList = new Waiting(userId, bookWaitlist.ListID ?? default(int));
                _context.WaitingPeople.Add(waitingList);
                _context.SaveChanges();
            }


            return(Ok());
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Removes a specific user favourite</remarks>
        /// <param name="id">id of Favourite to delete</param>
        /// <response code="200">OK</response>
        public virtual IActionResult UsersCurrentFavouritesIdDeletePostAsync(int id)
        {
            // get the current user id
            int?user_id = GetCurrentUserId();

            if (user_id != null)
            {
                bool exists = _context.UserFavourites.Where(x => x.User.Id == user_id)
                              .Any(a => a.Id == id);
                if (exists)
                {
                    var item = _context.UserFavourites.First(a => a.Id == id);

                    _context.UserFavourites.Remove(item);
                    // Save the changes
                    _context.SaveChanges();
                    return(new ObjectResult(item));
                }
                else
                {
                    // record not found
                    return(new StatusCodeResult(404));
                }
            }
            else
            {
                return(new StatusCodeResult(403));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create bulk rental afreement rate records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="201">RentalAgreementRate created</response>
        public virtual IActionResult RentalagreementratesBulkPostAsync(RentalAgreementRate[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (RentalAgreementRate item in items)
            {
                AdjustRecord(item);

                bool exists = _context.RentalAgreementRates.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.RentalAgreementRates.Update(item);
                }
                else
                {
                    _context.RentalAgreementRates.Add(item);
                }
            }

            // save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 6
0
        public virtual IActionResult RolesIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetRole.Any(x => x.RoleId == id);

            // not found
            if (!exists)
            {
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetRole role = _context.HetRole.First(x => x.RoleId == id);

            // remove associated role permission records
            List <HetRolePermission> itemsToRemove = _context.HetRolePermission
                                                     .Where(x => x.Role.RoleId == role.RoleId)
                                                     .ToList();

            foreach (HetRolePermission item in itemsToRemove)
            {
                _context.HetRolePermission.Remove(item);
            }

            // remove role and save
            _context.HetRole.Remove(role);
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(role)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Bulk create city records
        /// </summary>
        /// <remarks>Adds a number of cities</remarks>
        /// <param name="items"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult CitiesBulkPostAsync(City[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (City item in items)
            {
                bool exists = _context.Cities.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.Cities.Update(item);
                }
                else
                {
                    _context.Cities.Add(item);
                }
            }

            // Save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 8
0
        public virtual IActionResult UserDistrictsIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetUserDistrict.Any(a => a.UserDistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUserDistrict item = _context.HetUserDistrict
                                   .Include(x => x.User)
                                   .First(a => a.UserDistrictId == id);

            int userId = item.User.UserId;

            // remove record
            _context.HetUserDistrict.Remove(item);
            _context.SaveChanges();

            // return the updated user district records
            List <HetUserDistrict> result = _context.HetUserDistrict.AsNoTracking()
                                            .Include(x => x.User)
                                            .Include(x => x.District)
                                            .Where(x => x.User.UserId == userId)
                                            .ToList();

            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Bulk create user district records
        /// </summary>
        /// <remarks>Adds a number of user districts</remarks>
        /// <param name="items"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult UserDistrictsBulkPostAsync(UserDistrict[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (UserDistrict item in items)
            {
                bool exists = _context.UserDistricts.Any(a => a.Id == item.Id);

                if (item.District != null)
                {
                    item.District = _context.Districts.FirstOrDefault(a => a.Id == item.District.Id);
                }

                if (exists)
                {
                    _context.UserDistricts.Update(item);
                }
                else
                {
                    _context.UserDistricts.Add(item);
                }

                // Save the changes
                _context.SaveChanges();
            }

            return(new NoContentResult());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create bulk equipment attachment records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="200">Equipment created</response>
        public virtual IActionResult EquipmentAttachmentsBulkPostAsync(EquipmentAttachment[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (EquipmentAttachment item in items)
            {
                AdjustRecord(item);

                // determine if this is an insert or an update
                bool exists = _context.EquipmentAttachments.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.Update(item);
                }
                else
                {
                    _context.Add(item);
                }
            }

            // Save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> RentBookCopy()
        {
            //1- Check if this book is available
            //if yes: just add a new book copy
            //if not:  create a new book then add a new book copy in the db

            var userEmail = HttpContext.Items["Email"] as string;
            var user      = await _context.Users.FirstAsync(x => x.Email == userEmail);

            var userId = user.UserId ?? default(int);

            var cartItems = await _context.Carts.Where(x => x.UserId == userId).ToListAsync();

            foreach (var cartItem in cartItems)
            {
                var rentalContract = new RentalContract(userId, DateTime.Now.AddDays(21));
                _context.RentalContracts.Add(rentalContract);
                _context.SaveChanges();
                int id = rentalContract.ContractID ?? default(int);

                var lentBook = new Contains(id, cartItem.BookCopyId);
                _context.Contain.Add(lentBook);
                _context.SaveChanges();
            }

            foreach (var cartItem in cartItems)
            {
                _context.Carts.Remove(cartItem);
                _context.SaveChanges();
            }


            return(Ok());
        }
Exemplo n.º 12
0
        public virtual IActionResult DismissRolloverMessagePost([FromRoute] int id)
        {
            bool exists = _context.HetDistrictStatus.Any(a => a.DistrictId == id);

            // not found - return new status record
            if (!exists)
            {
                return(new ObjectResult(new HetsResponse(AnnualRolloverHelper.GetRecord(id, _context))));
            }

            // get record and update
            HetDistrictStatus status = _context.HetDistrictStatus
                                       .First(a => a.DistrictId == id);

            // ensure the process is complete
            if (status.DisplayRolloverMessage != null &&
                status.DisplayRolloverMessage == true &&
                status.ProgressPercentage != null &&
                status.ProgressPercentage == 100)
            {
                status.ProgressPercentage     = null;
                status.DisplayRolloverMessage = false;

                _context.SaveChanges();
            }

            // get status of current district
            return(new ObjectResult(new HetsResponse(AnnualRolloverHelper.GetRecord(id, _context))));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates several school buses
        /// </summary>
        /// <remarks>Used for bulk creation of schoolbus records.</remarks>
        /// <param name="body"></param>
        /// <response code="201">SchoolBus items created</response>

        public virtual IActionResult SchoolbusesBulkPostAsync(SchoolBus[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (SchoolBus item in items)
            {
                // adjust school bus owner
                AdjustSchoolBus(item);

                var exists = _context.SchoolBuss.Any(a => a.Id == item.Id);
                if (exists)
                {
                    _context.SchoolBuss.Update(item);
                }
                else
                {
                    _context.SchoolBuss.Add(item);
                }
            }
            // Save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 14
0
        public virtual IActionResult UsersIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetUser.Any(x => x.UserId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUser user = _context.HetUser.AsNoTracking()
                           .Include(x => x.HetUserRole)
                           .Include(x => x.HetUserDistrict)
                           .First(x => x.UserId == id);

            // delete user roles
            foreach (HetUserRole item in user.HetUserRole)
            {
                _context.HetUserRole.Remove(item);
            }

            // delete user districts
            foreach (HetUserDistrict item in user.HetUserDistrict)
            {
                _context.HetUserDistrict.Remove(item);
            }

            // delete user
            _context.HetUser.Remove(user);
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(user)));
        }
Exemplo n.º 15
0
        // Добавление заказчика
        public user AddUserCustomer(string fn, string ln, string mail)
        {
            user c = new user
            {
                firstName  = fn,
                secondName = ln,
                email      = mail,
                sysRole    = 1

                             /**
                              * SysRole:
                              * 1 - visitor
                              * 2 - employee
                              * 3 - owner
                              *
                              * Status
                              * 1 - customer
                              * 2 - seller
                              * 3 - manager
                              * 4 - admin
                              * 5 - owner
                              *
                              **/
            };

            db.users.Add(c);
            db.SaveChanges();
            return(c);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Create bulk area rottion list records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="201">DumpTruck created</response>
        public virtual IActionResult LocalarearotationlistsBulkPostAsync(LocalAreaRotationList[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (LocalAreaRotationList item in items)
            {
                // determine if this is an insert or an update
                bool exists = _context.LocalAreaRotationLists.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.Update(item);
                }
                else
                {
                    _context.Add(item);
                }
            }

            // Save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 17
0
        public virtual IActionResult UsersCurrentFavouritesIdDeletePost([FromRoute] int id)
        {
            // get the current user id
            string userId = _context.SmUserId;

            // not found
            if (userId == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            bool exists = _context.HetUserFavourite
                          .Where(x => x.User.SmUserId == userId)
                          .Any(a => a.UserFavouriteId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // delete favourite
            HetUserFavourite item = _context.HetUserFavourite.First(a => a.UserFavouriteId == id);

            _context.HetUserFavourite.Remove(item);

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(item)));
        }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Adds a number of districts.</remarks>
        /// <param name="items"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult ServiceareasBulkPostAsync(ServiceArea[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (ServiceArea item in items)
            {
                // avoid inserting a District if possible.
                int district_id = item.District.Id;
                var exists      = _context.Districts.Any(a => a.Id == district_id);
                if (exists)
                {
                    District district = _context.Districts.First(a => a.Id == district_id);
                    item.District = district;
                }

                exists = _context.ServiceAreas.Any(a => a.Id == item.Id);
                if (exists)
                {
                    _context.ServiceAreas.Update(item);
                }
                else
                {
                    _context.ServiceAreas.Add(item);
                }
            }
            // Save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 19
0
        /// <summary>
        ///  Basic file receiver for .NET Core
        /// </summary>
        /// <param name="id">Schoolbus Id</param>
        /// <param name="files">Files to add to attachments</param>
        /// <returns></returns>
        public IActionResult SchoolbusesIdAttachmentsPostAsync(int id, IList <IFormFile> files)
        {
            // validate the bus id
            bool exists = _context.SchoolBuss.Any(a => a.Id == id);

            if (exists)
            {
                SchoolBus schoolbus = _context.SchoolBuss
                                      .Include(x => x.Attachments)
                                      .Include(x => x.HomeTerminalCity)
                                      .Include(x => x.SchoolDistrict)
                                      .Include(x => x.SchoolBusOwner.PrimaryContact)
                                      .Include(x => x.District.Region)
                                      .Include(x => x.Inspector)
                                      .Include(x => x.CCWData)
                                      .First(a => a.Id == id);

                AddFilesToAttachments(schoolbus.Attachments, files);

                _context.SchoolBuss.Update(schoolbus);
                _context.SaveChanges();

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(schoolbus.Attachments);

                return(new ObjectResult(result));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create bulk group records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="201">Groups created</response>
        public IActionResult GroupsBulkPostAsync(Group[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (Group item in items)
            {
                bool exists = _context.Groups.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.Groups.Update(item);
                }
                else
                {
                    _context.Groups.Add(item);
                }
            }

            // save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Basic file receiver for .NET Core
        /// </summary>
        /// <param name="id">Schoolbus Id</param>
        /// <param name="files">Files to add to attachments</param>
        /// <returns></returns>
        public IActionResult EquipmentIdAttachmentsPostAsync(int id, IList <IFormFile> files)
        {
            // validate the bus id
            bool exists = _context.Equipments.Any(a => a.Id == id);

            if (exists)
            {
                Equipment equipment = _context.Equipments
                                      .Include(x => x.Attachments)
                                      .First(a => a.Id == id);

                AddFilesToAttachments(equipment.Attachments, files);

                _context.Equipments.Update(equipment);
                _context.SaveChanges();

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(equipment.Attachments);

                return(new ObjectResult(result));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Create bulk note records
        /// </summary>
        /// <param name="items"></param>
        /// <response code="201">Note created</response>
        public virtual IActionResult NotesBulkPostAsync(Note[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }

            foreach (Note item in items)
            {
                // determine if this is an insert or an update
                bool exists = _context.Notes.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.Update(item);
                }
                else
                {
                    _context.Add(item);
                }
            }

            // save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Adds a number of districts.</remarks>
        /// <param name="items"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult DistrictsBulkPostAsync(District[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (District item in items)
            {
                // avoid inserting a Region if possible.
                int region_id = item.Region.Id;
                var exists    = _context.Regions.Any(a => a.Id == region_id);
                if (exists)
                {
                    Region region = _context.Regions.First(a => a.Id == region_id);
                    item.Region = region;
                }

                exists = _context.Districts.Any(a => a.Id == item.Id);
                if (exists)
                {
                    _context.Districts.Update(item);
                }
                else
                {
                    _context.Districts.Add(item);
                }
            }
            // Save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Creates a new school bus
        /// </summary>
        /// <remarks>The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request.    The field value consists of a single absolute URI. </remarks>
        /// <param name="item"></param>
        /// <response code="201">SchoolBus created</response>

        public virtual IActionResult AddBusAsync(SchoolBus item)
        {
            // adjust school bus owner

            if (item.SchoolBusOwner != null)
            {
                int  school_bus_owner_id     = item.SchoolBusOwner.Id;
                bool school_bus_owner_exists = _context.SchoolBusOwners.Any(a => a.Id == school_bus_owner_id);
                if (school_bus_owner_exists)
                {
                    SchoolBusOwner school_bus_owner = _context.SchoolBusOwners.First(a => a.Id == school_bus_owner_id);
                    item.SchoolBusOwner = school_bus_owner;
                }
            }

            // adjust service area.

            if (item.ServiceArea != null)
            {
                int  service_area_id     = item.ServiceArea.Id;
                bool service_area_exists = _context.ServiceAreas.Any(a => a.Id == service_area_id);
                if (service_area_exists)
                {
                    ServiceArea service_area = _context.ServiceAreas.First(a => a.Id == service_area_id);
                    item.ServiceArea = service_area;
                }
            }

            // adjust school district

            if (item.SchoolBusDistrict != null)
            {
                int  schoolbus_district_id     = item.SchoolBusDistrict.Id;
                bool schoolbus_district_exists = _context.SchoolDistricts.Any(a => a.Id == schoolbus_district_id);
                if (schoolbus_district_exists)
                {
                    SchoolDistrict school_district = _context.SchoolDistricts.First(a => a.Id == schoolbus_district_id);
                    item.SchoolBusDistrict = school_district;
                }
            }

            // adjust home city

            if (item.HomeTerminalCity != null)
            {
                int  city_id     = item.HomeTerminalCity.Id;
                bool city_exists = _context.Cities.Any(a => a.Id == city_id);
                if (city_exists)
                {
                    City city = _context.Cities.First(a => a.Id == city_id);
                    item.HomeTerminalCity = city;
                }
            }

            _context.SchoolBuss.Add(item);
            _context.SaveChanges();
            return(new ObjectResult(item));
        }
Exemplo n.º 25
0
 public ActionResult Create([Bind(Include = "NoticeId,NoticeDescription,NoticeDate")] Notice notice)
 {
     if (ModelState.IsValid)
     {
         db.Notices.Add(notice);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(notice));
 }
Exemplo n.º 26
0
        /// <summary>
        ///
        /// </summary>

        /// <param name="body"></param>
        /// <response code="201">Inspections created</response>

        public virtual IActionResult InspectionsBulkPostAsync(Inspection[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (Inspection item in items)
            {
                // adjust the user
                if (item.Inspector != null)
                {
                    int  user_id     = item.Inspector.Id;
                    bool user_exists = _context.Users.Any(a => a.Id == user_id);
                    if (user_exists)
                    {
                        User user = _context.Users.First(a => a.Id == user_id);
                        item.Inspector = user;
                    }
                    else
                    {
                        item.Inspector = null;
                    }
                }
                // adjust the schoolbus
                if (item.SchoolBus != null)
                {
                    int  schoolbus_id     = item.SchoolBus.Id;
                    bool schoolbus_exists = _context.SchoolBuss.Any(a => a.Id == schoolbus_id);
                    if (schoolbus_exists)
                    {
                        SchoolBus schoolbus = _context.SchoolBuss.First(a => a.Id == schoolbus_id);
                        item.SchoolBus = schoolbus;
                    }
                    else
                    {
                        item.SchoolBus = null;
                    }
                }
                bool exists = _context.Inspections.Any(a => a.Id == item.Id);
                if (exists)
                {
                    _context.Inspections.Update(item);
                }
                else
                {
                    // Inspection has a special field, createdDate which is set to now.
                    item.CreatedDate = DateTime.UtcNow;
                    _context.Inspections.Add(item);
                }
            }
            // Save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
        public virtual IActionResult EquipmentIdAttachmentsPost([FromRoute] int id, [FromForm] IList <IFormFile> files)
        {
            // validate the id
            bool exists = _context.HetEquipment.Any(a => a.EquipmentId == id);

            if (!exists)
            {
                return(new StatusCodeResult(404));
            }

            HetEquipment equipment = _context.HetEquipment
                                     .Include(x => x.HetDigitalFile)
                                     .First(a => a.EquipmentId == id);

            foreach (IFormFile file in files)
            {
                if (file.Length > 0)
                {
                    HetDigitalFile attachment = new HetDigitalFile();

                    // strip out extra info in the file name
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        attachment.FileName = Path.GetFileName(file.FileName);
                    }

                    // allocate storage for the file and create a memory stream
                    attachment.FileContents = new byte[file.Length];

                    using (MemoryStream fileStream = new MemoryStream(attachment.FileContents))
                    {
                        file.CopyTo(fileStream);
                    }

                    attachment.Type = GetType(attachment.FileName);

                    // set the mime type id
                    int?mimeTypeId = StatusHelper.GetMimeTypeId(attachment.Type, _context);
                    if (mimeTypeId == null)
                    {
                        throw new DataException("Mime Type Id cannot be null");
                    }

                    attachment.MimeTypeId = (int)mimeTypeId;

                    equipment.HetDigitalFile.Add(attachment);
                }
            }

            _context.SaveChanges();

            return(new ObjectResult(equipment.HetDigitalFile));
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>

        /// <param name="body"></param>
        /// <response code="201">Inspections created</response>

        public virtual IActionResult InspectionsBulkPostAsync(Inspection[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (Inspection item in items)
            {
                _context.Inspections.Add(item);
            }
            // Save the changes
            _context.SaveChanges();
            return(new NoContentResult());
        }
Exemplo n.º 29
0
        public async Task PopulateCCWJob()
        {
            await Task.CompletedTask;

            var enableCcwCreate = (_configuration["ENABLE_HANGFIRE_CREATE"] ?? "N").ToUpperInvariant() == "Y";

            if (!enableCcwCreate)
            {
                return;
            }

            // sanity check
            if (_userId != null && _userGuid != null && _userDir != null)
            {
                // make a database connection and see if there are any records that are missing the CCW link.
                // we restrict the query to records not updated in the last 6 hours so that the batch process does not repeatedly try a failed record.
                var data = _context.SchoolBuss
                           .FirstOrDefault(x => x.CCWDataId == null && x.LastUpdateTimestamp < DateTime.UtcNow.AddHours(-6));

                if (data == null)
                {
                    return;
                }

                data.LastUpdateTimestamp = DateTime.UtcNow;

                // get the data for the request from the result of the database query.
                string regi  = data.ICBCRegistrationNumber;
                string vin   = data.VehicleIdentificationNumber;
                string plate = data.LicencePlateNumber;

                // Fetch the record.
                CCWData cCWData = _ccwDataService.GetCCW(regi, plate, vin, _userId, _userGuid, _userDir);

                if (cCWData == null)
                {
                    _logger.LogInformation($"[Hangfire] PopulateCCWJob - No data from CCW for regi: {regi} vin: {vin}, plate: {plate}.");
                    _context.SaveChanges();
                    _logger.LogInformation($"[Hangfire] PopulateCCWJob - Updated bus record timestamp with the ID {data.Id}.");
                    return;
                }

                data.CCWData = cCWData;

                // ensure that the record is touched in the database
                _context.SaveChanges();
                _logger.LogInformation($"[Hangfire] PopulateCCWJob - Saved bus record with the ID {data.Id}.");
            }
        }
Exemplo n.º 30
0
        /// <summary>
        ///
        /// </summary>

        /// <param name="items"></param>
        /// <response code="201">SchoolBusOwnerNotes created</response>

        public virtual IActionResult SchoolbusownernotesBulkPostAsync(SchoolBusOwnerNote[] items)
        {
            if (items == null)
            {
                return(new BadRequestResult());
            }
            foreach (SchoolBusOwnerNote item in items)
            {
                _context.SchoolBusOwnerNotes.Add(item);
            }
            // Save the changes
            _context.SaveChanges();

            return(new NoContentResult());
        }