예제 #1
0
        public async Task <ServiceResponse <ConfiguredLaptopModel> > PostConfiguredLaptop(ConfiguredLaptopModel configuredLaptopModel)
        {
            try
            {
                var basketItems = await _context.ConfiguredLaptops.ToListAsync();


                var checkItem = await _context.ConfiguredLaptops
                                .Include(i => i.ConfigurationItems)
                                //.Include(i => i.Laptop)
                                .FirstOrDefaultAsync(f =>
                                                     f.LaptopId == configuredLaptopModel.Laptop.Id);


                //f.ConfigurationItems.Equals(configuredLaptopModel.ConfigurationItems));

                var entity = _mapper.Map <ConfiguredLaptop>(configuredLaptopModel);

                if (checkItem != null)
                {
                    if (checkItem.LaptopId.Equals(entity.LaptopId) && checkItem.ConfigurationItems.Equals(entity.ConfigurationItems))
                    {
                    }

                    return(new ServiceResponse <ConfiguredLaptopModel>
                    {
                        ErrorCode = HttpStatusCode.Conflict,
                        ErrorDescription = "Laptop Brand with same configuration already added to basket"
                    });
                }



                _context.Entry(entity).State = EntityState.Added;

                if (await _context.SaveChangesAsync() > 0)
                {
                    return(new ServiceResponse <ConfiguredLaptopModel>
                    {
                        Data = configuredLaptopModel
                    });
                }

                return(new ServiceResponse <ConfiguredLaptopModel>
                {
                    ErrorCode = HttpStatusCode.InternalServerError,
                    ErrorDescription = "Internal Server Error"
                });
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(new ServiceResponse <ConfiguredLaptopModel>
                {
                    ErrorCode = HttpStatusCode.InternalServerError,
                    ErrorDescription = "Internal Server Error"
                });
            }
        }
예제 #2
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dbContext.Entry(entity).State = EntityState.Modified;
 }