Exemple #1
0
        public async Task <int> SeedRetailerEntitiesFromJson(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException($"Value of {filePath} must be supplied to {nameof(SeedRetailerEntitiesFromJson)}");
            }

            if (!File.Exists(filePath))
            {
                throw new ArgumentException($"The file '{filePath}' does not exist");
            }

            var dataSet  = File.ReadAllText(filePath);
            var seedData = JsonConvert.DeserializeObject <List <RetailerDbo> >(dataSet, new IsoDateTimeConverter {
                DateTimeFormat = "dd/MM/yyyy"
            });

            // When seeding objects with links to a reference table, we need to ensure we can pass in just the id of the referenced table (in this instance: ExternalSystemId)
            // Creating an object of the referenced entity will unsurprisingly create a new record in the database, breaking our intended references.

            _context.Retailers.AddRange(seedData);

            return(await _context.SaveChangesAsync());
        }
Exemple #2
0
        public async Task <RequestDbo> AddOrUpdate(RequestDbo request)
        {
            try
            {
                Log.Debug($"{nameof(AddOrUpdate)} called on {nameof(RequestRepository)}");

                _context.Requests.Update(request);
                request.Id = await _context.SaveChangesAsync();

                Log.Debug($"Request saved in method {nameof(AddOrUpdate)} called on {nameof(RequestRepository)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Error($"Error in method {nameof(AddOrUpdate)} in {nameof(RequestRepository)}");
            }

            return(request);
        }
        public async Task <ExternalSystemDbo> AddOrUpdate(ExternalSystemDbo externalSystem)
        {
            try
            {
                Log.Debug($"{nameof(AddOrUpdate)} called on {nameof(ExternalSystemRepository)}");

                _context.ExternalSystems.Update(externalSystem);
                externalSystem.Id = await _context.SaveChangesAsync();

                Log.Debug($"ExternalSystem saved in method {nameof(AddOrUpdate)} called on {nameof(ExternalSystemRepository)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Error($"Error in method {nameof(AddOrUpdate)} in {nameof(ExternalSystemRepository)}");
            }

            return(externalSystem);
        }
        public async Task <StaffMemberDbo> AddOrUpdate(StaffMemberDbo staffMember)
        {
            try
            {
                Log.Debug($"{nameof(AddOrUpdate)} called on {nameof(StaffMemberRepository)}");

                _context.StaffMembers.Update(staffMember);
                staffMember.Id = await _context.SaveChangesAsync();

                Log.Debug($"StaffMember saved in method {nameof(AddOrUpdate)} called on {nameof(StaffMemberRepository)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Error($"Error in method {nameof(AddOrUpdate)} in {nameof(StaffMemberRepository)}");
            }

            return(staffMember);
        }
        public async Task <AreaManagerDbo> AddOrUpdate(AreaManagerDbo areaManager)
        {
            try
            {
                Log.Debug($"{nameof(AddOrUpdate)} called on {nameof(AreaManagerRepository)}");

                _context.AreaManagers.Update(areaManager);
                areaManager.Id = await _context.SaveChangesAsync();

                Log.Debug($"AreaManager saved in method {nameof(AddOrUpdate)} called on {nameof(AreaManagerRepository)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Error($"Error in method {nameof(AddOrUpdate)} in {nameof(AreaManagerRepository)}");
            }

            return(areaManager);
        }
Exemple #6
0
        public async Task <BrandDbo> AddOrUpdate(BrandDbo brand)
        {
            try
            {
                Log.Debug($"{nameof(AddOrUpdate)} called on {nameof(BrandRepository)}");

                _context.Brands.Update(brand);
                brand.Id = await _context.SaveChangesAsync();

                Log.Debug($"Brand saved in method {nameof(AddOrUpdate)} called on {nameof(BrandRepository)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Log.Error($"Error in method {nameof(AddOrUpdate)} in {nameof(BrandRepository)}");
            }

            return(brand);
        }