Esempio n. 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"
                });
            }
        }
Esempio n. 2
0
        public async Task <User> Register(User user, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Esempio n. 3
0
 public async Task <bool> SaveAll()
 {
     return(await _context.SaveChangesAsync() > 0);
 }