Esempio n. 1
0
        public async Task <bool> Edit(string id, ProblemServiceModel problemServiceModel)
        {
            var problemFromDb = await this.dbContext.Problems.SingleOrDefaultAsync(x => x.Id == id);

            if (problemFromDb == null)
            {
                throw new ArgumentNullException(nameof(problemFromDb));
            }

            problemFromDb.NeedTechnician = problemServiceModel.NeedTechnician;
            problemFromDb.Description    = problemServiceModel.Description;

            this.dbContext.Update(problemFromDb);
            int result = await this.dbContext.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 2
0
        public async Task <ProblemServiceModel> GetProblemById(string id)
        {
            var problemFromDb = await this.dbContext.Problems.SingleOrDefaultAsync(x => x.Id == id);

            if (problemFromDb == null)
            {
                throw new ArgumentNullException(nameof(problemFromDb));
            }

            ProblemServiceModel problem = new ProblemServiceModel
            {
                Date           = problemFromDb.Date,
                Description    = problemFromDb.Description,
                NeedTechnician = problemFromDb.NeedTechnician,
                CustomerId     = problemFromDb.CustomerId
            };

            return(problem);
        }
Esempio n. 3
0
        public async Task <bool> Create(ProblemServiceModel problemServiceModel)
        {
            var customerFromDb = await this.dbContext.Users.SingleOrDefaultAsync(x => x.Id == problemServiceModel.CustomerId);

            if (customerFromDb == null)
            {
                throw new ArgumentNullException(nameof(customerFromDb));
            }

            Problem problem = new Problem
            {
                Description    = problemServiceModel.Description,
                Date           = problemServiceModel.Date,
                NeedTechnician = problemServiceModel.NeedTechnician
            };

            problem.Customer = (RichStoreUser)customerFromDb;

            await this.dbContext.Problems.AddAsync(problem);

            int result = await this.dbContext.SaveChangesAsync();

            return(result > 0);
        }