Exemplo n.º 1
0
        public async Task <ResultDTO> AddReview([FromBody] ReviewAddDTO model)
        {
            try
            {
                var review = _mapper.Map <ReviewAddDTO, Review>(model);
                await _context.reviews.AddAsync(review);

                await _context.SaveChangesAsync();

                return(new ResultDTO
                {
                    Status = 200,
                    Message = "Posted"
                });
            }
            catch (Exception ex)
            {
                var temp = new List <string>();
                temp.Add(ex.Message);
                return(new ResultErrorDTO
                {
                    Status = 500,
                    Message = "Error",
                    Errors = temp
                });
            }
        }
Exemplo n.º 2
0
        public async Task Birthday(DateTime date)
        {
            var birthday = await _database.Birthday.FirstOrDefaultAsync(owner => owner.UserId == Context.User.Id);

            var newBirthday = new Birthday
            {
                Date      = date,
                DoDisplay = true,
                UserId    = Context.User.Id,
                User      = await _misc.GetOrCreateUser(Context.User.Id)
            };

            try
            {
                if (birthday != null)
                {
                    _database.Birthday.Update(newBirthday);
                    await ReplyAsync("Your birthday has been updated!");
                }
                else
                {
                    await _database.Birthday.AddAsync(newBirthday);
                    await ReplyAsync("Your birthday has been added!");
                }
                await _database.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
        public async Task GiveCoins(IUser usr, ulong amount)
        {
            var user = await _miscDb.GetOrCreateUser(Context.User.Id);

            var receiver = await _miscDb.GetOrCreateUser(usr.Id);

            if (usr.Id == Context.User.Id)
            {
                await ReplyAsync($"You've sent {amount} coins to yourself");

                return;
            }

            if (user.Coins < amount)
            {
                await ReplyAsync("You don't have that much coins, use $coins to check them!");

                return;
            }

            user.Coins     -= amount;
            receiver.Coins += amount;

            _db.UserData.Update(receiver);
            _db.UserData.Update(user);
            await _db.SaveChangesAsync();

            await ReplyAsync($"You gave {usr.Username} {amount} coins!");
        }
        public async Task <IActionResult> PutCar(int id, Car car)
        {
            if (id != car.Id)
            {
                return(BadRequest());
            }

            _context.Entry(car).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task SelectClass(string userClass)
        {
            var dbClass = await _database.userclass.FirstOrDefaultAsync(x => x.Name.ToLower() == userClass.ToLower());

            if (dbClass == null)
            {
                await ReplyAsync("This class doesn't exist");

                return;
            }

            //TODO
            var gear = await _gearDatabase.GetOrCreateGearAsync(Context.User.Id);

            if (gear.UserClass.Name != UserClasses.Pleb)
            {
                await ReplyAsync("You cannot change your class currently");

                return;
            }

            gear.UserClass = dbClass;
            _database.gear.Update(gear);
            await _database.SaveChangesAsync();

            await ReplyAsync($"You've changed your class to {dbClass.Name}");
        }
Exemplo n.º 6
0
        public async Task <PayPros> Post(int id, [FromBody] PayPros payment)
        {
            //Get item to be paid from id
            var item = new { id = id, balance = 1.00 };

            #region PayPros
            //Process Payment
            EFContext _dbContext = new EFContext();

            //Be secure, remove full CC from persistent storage record
            string FullCCNum = payment.CreditCardNumber;
            payment = PaymentProcessing.EncryptCreditCardNumber(payment);
            //Save payment attempt to persistent storage
            _dbContext.PayPros.Add(payment);
            await _dbContext.SaveChangesAsync();

            //Process with paypros
            PaymentProcessing payProcessing = new PaymentProcessing(PaymentAccounts.Judicial, PaymentMethods.Web);
            payment = payProcessing.Initiate(payment, FullCCNum);
            //Save updated payment attempt to persistent storage
            _dbContext.PayPros.Update(payment);
            await _dbContext.SaveChangesAsync();

            #endregion

            //Update item if payment is successful
            if (payment.responseCode == 1)
            {
                item.balance = 0.00;
            }

            return(payment);
        }
Exemplo n.º 7
0
        public async Task <User> AddAsync(User newUser, CancellationToken ct = default(CancellationToken))
        {
            _context.User.Add(newUser);
            await _context.SaveChangesAsync(ct);

            return(newUser);
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create(AddUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _context.Users.FirstOrDefaultAsync(x => x.Email.Equals(model.Email));

                if (user != null)
                {
                    user.Counter++;
                    _context.Entry(user).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.Users.Add(new Entities.User
                    {
                        Email = model.Email,
                        Name  = model.Name
                    });
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public async Task <Result> AddUser(User user)
        {
            var result = new Result();

            try
            {
                if (user == null)
                {
                    throw new ArgumentNullException(nameof(user));
                }
                await _context.AddAsync <User>(user);

                var operationResult = await _context.SaveChangesAsync();

                if (operationResult != 1)
                {
                    throw new OperationCanceledException(nameof(operationResult));
                }
                result.IsCompleted = true;
            }
            catch (Exception ex)
            {
                result.Message     = _builder.Build(ex.Message, nameof(EFUserRepository), nameof(AddUser));
                result.IsCompleted = false;
            }
            return(result);
        }
Exemplo n.º 10
0
        public async Task <Address> AddAsync(Address newAddress, CancellationToken ct = default(CancellationToken))
        {
            _context.Address.Add(newAddress);
            await _context.SaveChangesAsync(ct);

            return(newAddress);
        }
        public async Task <IActionResult> PutAirport(int id, Airport airport)
        {
            if (id != airport.ID)
            {
                return(BadRequest());
            }

            _context.Entry(airport).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AirportExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("Id,FirstName,LastName")] Member member)
        {
            if (id != member.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(member);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemberExists(member.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(member));
        }
        public async Task <ResultDTO> AddNewGame([FromBody] GameAddDTO game)
        {
            Game newGame = new Game();

            newGame.GameKey     = Guid.NewGuid().ToString();
            newGame.Title       = game.title;
            newGame.Price       = game.price;
            newGame.Description = game.description;
            newGame.ImageURL    = game.imageURL;
            newGame.Year        = game.year;
            newGame.Developer   = _context.Developers.FirstOrDefault(x => x.Name == game.developer);
            newGame.Genre       = _context.Genres.FirstOrDefault(x => x.Name == game.genre);

            // newDeveloper.Id = _context.Developers.LastOrDefault().Id+1;


            await _context.Games.AddAsync(newGame);

            await _context.SaveChangesAsync();

            return(new ResultDTO
            {
                Status = 200,
                Message = "Item added"
            });
        }
Exemplo n.º 14
0
        public async Task <IActionResult> PutTours([FromRoute] long id, [FromBody] Tour tour)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tour.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tour).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TourExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Name, Color")] ChannelModel channelModel)
        {
            UserModel user = await UserManager.GetUserAsync(User);

            var existChannel = _context.Channels.Where(c => c.Name == channelModel.Name).Include(c => c.UserAuthor).SingleOrDefault();

            if (ModelState.IsValid && (existChannel == null || existChannel.UserAuthor.UserName != user.UserName))
            {
                channelModel.UserAuthor = user;

                _context.Channels.Add(channelModel);
                await _context.SaveChangesAsync();

                channelModel = _context.Channels.Where(c => c.Name == channelModel.Name).Include(c => c.UserAuthor).Where(c => c.UserAuthor.UserName == user.UserName).Single();

                UserChannelModel userChannel = new UserChannelModel();
                userChannel.UserID    = user.Id;
                userChannel.ChannelID = channelModel.ID;

                _context.UserChannels.Add(userChannel);
                await _context.SaveChangesAsync();

                return(Redirect("/Channel/Details/" + channelModel.ID));
            }
            else
            {
                ViewBag.info = "kanał już istnieje!";
            }
            return(View(channelModel));
        }
Exemplo n.º 16
0
        public async Task <UserData> GetOrCreateUser(ulong userId)
        {
            // var user = await _db.UserData.FirstOrDefaultAsync(user => user.UserId == userId);
            var user = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(_db.UserData, user => user.UserId == userId);

            if (user != null)
            {
                return(user);
            }

            var userInfo = new UserData
            {
                UserId        = userId,
                UserName      = _client.GetUser(userId).Username,
                Coins         = 0,
                CurrentQuest  = null,
                Level         = 1,
                UserDaily     = false,
                EggplantDaily = false
            };

            await _db.UserData.AddAsync(userInfo);

            await _db.SaveChangesAsync();

            return(userInfo);
        }
Exemplo n.º 17
0
        public async Task <bool> DeleteTeacher(int[] ids)
        {
            try
            {
                foreach (var id in ids)
                {
                    var teacher = _context.Teachers.Where((item) => item.Id == id).FirstOrDefault();

                    if (teacher != null)
                    {
                        var group = _context.Groups.FirstOrDefault((item) => item.TeacherId == teacher.Id);
                        if (group != null)
                        {
                            await _groupService.DeleteGroup((int)group.Id);
                        }


                        _context.Teachers.Remove(teacher);

                        await _context.SaveChangesAsync();

                        var user = _context.Users.FirstOrDefault((item) => item.Id == id);
                        if (user != null)
                        {
                            await _userManager.DeleteAsync(user);
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 18
0
        public async Task <ActionResult <Account> > PostAccount(AccountDTO accountDto)
        {
            var result = await new UsersController(_context).GetUser(accountDto.UserId);

            if (result.Value == null)
            {
                return(NotFound());
            }
            if (!AccountValidation.CanUserCreateAccount(result.Value))
            {
                return(ValidationProblem("User's gross monthly income is below the required amount ($1000)"));
            }

            var account = new Account
            {
                AccountId    = accountDto.AccountId,
                AccountLimit = accountDto.AccountLimit,
                UserId       = accountDto.UserId,
                CreationDate = DateTime.Now
            };

            _context.Accounts.Add(account);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAccount", new { id = account.AccountId }, account));
        }
Exemplo n.º 19
0
        public async Task <IActionResult> PutStudent(Guid id, Student student)
        {
            if (id != student.Id)
            {
                return(BadRequest());
            }

            _context.Entry(student).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create(int?id, [Bind("DescripcionAtencion")] Evolucion evolucion)
        {
            if (ModelState.IsValid)
            {
                evolucion.Medico        = User.Identity.Name;
                evolucion.FechaYHora    = DateTime.Now;
                evolucion.EstadoAbierto = true;
                evolucion.EpisodioId    = (int)id;

                Episodio e = _context.Episodios.Where(e => e.Id == id).FirstOrDefault();
                evolucion.Episodio = e;
                evolucion.Notas    = new List <Nota>();

                if (e.Evoluciones == null)
                {
                    e.Evoluciones = new List <Evolucion>();
                }
                e.Evoluciones.Add(evolucion);

                _context.Add(evolucion);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id }));
            }
            return(View(evolucion));
        }
Exemplo n.º 21
0
        /// <summary>
        /// 删
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <bool> Del(T entity)
        {
            db.Entry(entity).State = EntityState.Deleted;
            int i = await db.SaveChangesAsync();

            return(i > 0);
        }
Exemplo n.º 22
0
        public async Task <ResultDTO> AddActor([FromBody] ActorAddDTO model)
        {
            try
            {
                var actor = _mapper.Map <ActorAddDTO, Actor>(model);
                await _context.actors.AddAsync(actor);

                await _context.SaveChangesAsync();

                return(new ResultDTO
                {
                    Status = 200,
                    Message = "Posted"
                });
            }
            catch (Exception ex)
            {
                List <string> temp = new List <string>();
                temp.Add(ex.Message);
                return(new ResultErrorDTO
                {
                    Status = 500,
                    Message = "Error",
                    Errors = temp
                });
            }
        }
Exemplo n.º 23
0
        public async Task <T> Add(T entity, CancellationToken cancellationToken)
        {
            await entities.AddAsync(entity);

            await context.SaveChangesAsync(cancellationToken);

            return(entity);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Creating a user
        /// </summary>
        /// <param name="obj">user to create</param>
        /// <returns>created user</returns>
        public async Task <User> Create(User obj)
        {
            var added = await context.Users.AddAsync(obj).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(added.Entity);
        }
        public async Task <int> CreateAsync(ClassificationCriterionDTO dto)
        {
            var entity = dto.ConvertToEntity();

            _context.Add(entity);
            await _context.SaveChangesAsync();

            return(entity.Id);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Create User
        /// </summary>
        public async Task <RoleModel> Create(RoleModel insertModel)
        {
            var role = _mapper.Map <Role>(insertModel);
            await _efContext.Role.AddAsync(role);

            await _efContext.SaveChangesAsync();

            return(insertModel);
        }
Exemplo n.º 27
0
        public async Task <int> CreateAsync(FieldDTO dto)
        {
            var entity = dto.ConvertToEntity();

            _context.Add(entity);
            await _context.SaveChangesAsync();

            return(entity.Id);
        }
Exemplo n.º 28
0
        public async Task ConfigurePrefix(string prefix)
        {
            var server = await _miscDb.GetOrCreateServer(Context.Guild.Id);

            server.prefix = Char.Parse(prefix);
            _dataBase.ServersSettings.Update(server);
            await _dataBase.SaveChangesAsync();

            await ReplyAsync("Server prefix to H.u.e database");
        }
Exemplo n.º 29
0
        public virtual async Task CreateAsync(T item)
        {
            if (item == null)
            {
                throw new Exception("Значения модели не описаны");
            }
            await _context.Set <T>().AddAsync(item);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 30
0
        /// <summary>
        /// 更新公司信息
        /// </summary>
        /// <param name="companyInfo"></param>
        /// <returns></returns>
        public async Task <JsonResult> UpdateCompanyInfo(CompanyInfo companyInfo)
        {
            _db.Company.Update(companyInfo);
            ResponseTemplate response = new ResponseTemplate();

            response.Success = true;
            response.Data    = await _db.SaveChangesAsync();

            return(Json(response));
        }