Exemplo n.º 1
0
        private static async Task ProcessMessage(string message)
        {
            var start = DateTimeOffset.UtcNow;

            var json = JObject.Parse(message);
            var id   = json["value"].Value <int>();

            using (var db = new DemoContext())
            {
                var task = await db.Tasks.Where(t => t.Id == id).FirstOrDefaultAsync();

                if (task != null)
                {
                    task.Status  = WorkerTaskStatus.Running;
                    task.Started = start;

                    for (var t = 0; t <= 100; t += 10)
                    {
                        task.Progress = t;
                        task.Updated  = DateTimeOffset.UtcNow;
                        await db.SaveChangesAsync();
                    }

                    task.Progress = 100;
                    task.Updated  = DateTimeOffset.UtcNow;
                    task.Status   = WorkerTaskStatus.Completed;
                    await db.SaveChangesAsync();
                }
            }
        }
Exemplo n.º 2
0
        public async Task <bool> Create([FromForm] User user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Nome,Email")] Cliente cliente)
        {
            if (id != cliente.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cliente);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClienteExists(cliente.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> EditPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var userToUpdate = await _context.Users.SingleOrDefaultAsync(s => s.UserId == id);

            if (await TryUpdateModelAsync <User>(
                    userToUpdate,
                    "",
                    s => s.FirstName, s => s.LastName))
            {
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View(userToUpdate));
        }
        public async Task <IActionResult> PutContact(int id, Contact contact)
        {
            if (id != contact.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 7
0
        public async Task <Warrior> Add(Warrior warrior)
        {
            _context.Warrior.Add(warrior);
            await _context.SaveChangesAsync();

            return(warrior);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("FirstName, LastName")] Author author)
        {
            _context.Add(author);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PutFatura([FromRoute] long id, [FromBody] Fatura fatura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != fatura.FaturaId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> PutPareja(int id, Pajera pareja)
        {
            if (id != pareja.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PutDependents(int id, Dependents dependents)
        {
            if (id != dependents.dependent_id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task AddPlayers(Player player, Game game)
        {
            player.Game = game;

            _context.Players.AddRange(player);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Title, AuthorId")] Book book)
        {
            _context.Books.Add(book);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,BlogId,Url")] Blog blog)
        {
            if (id != blog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogExists(blog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> PutRegions(int id, Regions regions)
        {
            if (id != regions.region_id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 17
0
        public async Task <IActionResult> PutAsset(int id, Asset asset)
        {
            if (id != asset.Id)
            {
                return(BadRequest());
            }

            _context.Entry(asset).State = EntityState.Modified;
            List <Variant> variants = GetVariants(asset);

            asset.SetVariants(variants);

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCustomerDetailList(string id, CustomerDetailList customerDetailList)
        {
            if (id != customerDetailList.CustomerName)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 19
0
        public async Task <IActionResult> EditPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var user = _context.Users.FirstOrDefault(b => b.UserId == id);

            var jobToUpdate = await _context.Jobs.SingleOrDefaultAsync(s => s.JobId == id);

            jobToUpdate.AssignedTo = user;

            if (await TryUpdateModelAsync <Job>(
                    jobToUpdate,
                    "",
                    s => s.Title, s => s.DueDate, s => s.IsComplete, s => s.AssignedTo))
            {
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }

            ViewBag.UserId = new SelectList(_context.Users, "UserId", "FullName");
            return(View(jobToUpdate));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> PutGoogleRoadIcon([FromRoute] int id, [FromBody] GoogleRoadIcon googleRoadIcon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public async Task <Result> Handle(GridValueChangeCommand request, CancellationToken cancellationToken)
        {
            //TODO: Add transaction
            await SetProperty(request.AgregateId, request.PropertyName, request.NewValue, request.OldValue);

            var newEvent = new ValueChangedEvent
            {
                PropertyName = request.PropertyName,
                NewValue     = request.NewValue,
                OldValue     = request.OldValue,
                AgregateId   = request.AgregateId,
                AgregateType = typeof(Item),
            };

            await eventStore.Add(new EventData <ValueChangedEvent>
            {
                AgregateId   = newEvent.AgregateId,
                AgregateType = newEvent.AgregateType,
                Caller       = 99999999,
                CallerName   = "test",
                CreatedAt    = DateTime.Now,
                Data         = newEvent
            });

            await context.SaveChangesAsync();

            await eventBus.Publish(newEvent);

            return(await Task.FromResult(Result.Success()));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> UpdateUser([FromRoute] long id, [FromBody] UserModel.UserForCreate user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var originUser = _context.User.SingleOrDefault(u => u.Id == id);

            if (originUser == null)
            {
                return(NotFound());
            }

            originUser.UserName           = user.Username;
            originUser.NormalizedEmail    = user.EmailAddress.ToUpper();
            originUser.Name               = user.Name;
            originUser.IsActive           = user.IsActive;
            originUser.Surname            = user.Surname;
            originUser.NormalizedUserName = user.Username.ToUpper();
            originUser.Email              = user.EmailAddress;
            originUser.EmailConfirmed     = user.SendActivationEmail;

            if (!string.IsNullOrEmpty(user.Password))
            {
                var passwd = _userManager.PasswordHasher.HashPassword(originUser, user.Password);
                originUser.PasswordHash = passwd;
            }

            try
            {
                await _context.SaveChangesAsync();

                var currentUserRoles = _context.UserRoles.Where(r => r.UserId == user.Id);

                _context.UserRoles.RemoveRange(currentUserRoles);

                foreach (var roleName in user.AssignedRoleNames)
                {
                    var role = _context.Role.SingleOrDefault(r => r.RoleName == roleName);
                    if (role != null)
                    {
                        await _context.UserRoles.AddAsync(new UserRole(originUser.Id, role.Id));
                    }
                }
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetUser", new { id = originUser.Id }, originUser));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 23
0
        public async Task <Camp> AddCamp(Camp camp)
        {
            var camps = await _context.Camps.AddAsync(camp);

            await _context.SaveChangesAsync();

            return(camps.Entity);
        }
Exemplo n.º 24
0
        public async Task <RxJob> AddAsync(RxJob job)
        {
            await _context.RxJob.AddAsync(job);

            await _context.SaveChangesAsync();

            return(job);
        }
Exemplo n.º 25
0
        public async Task <T> AddAsync(T entity)
        {
            await DbContext.Set <T>().AddAsync(entity);

            await DbContext.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 26
0
        public async Task <School> AddSchool(School school)
        {
            var schools = await _context.Schools.AddAsync(school);

            await _context.SaveChangesAsync();

            return(schools.Entity);
        }
        public async Task <ToDoItem> AddAsync(ToDoItem newItem)
        {
            _context.ToDoItems.Add(newItem);

            await _context.SaveChangesAsync();

            return(newItem);
        }
Exemplo n.º 28
0
        public async Task <Tabla> Add(Tabla entity)
        {
            await _context.Tabla.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task <User> UpdateAsync(User user)
        {
            User existing = await _context.Users.FindAsync(user.Id);

            _userBuilder.Map(user, existing);
            await _context.SaveChangesAsync();

            return(user);
        }
Exemplo n.º 30
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,DOB")] Owner owner)
        {
            if (ModelState.IsValid)
            {
                _context.Add(owner);
                await _context.SaveChangesAsync();

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