Example #1
0
        public Profile CreateProfile(Profile profile)
        {
            _profilecontext.Profiles.Add(profile);
            _profilecontext.SaveChanges();

            return(profile);
        }
Example #2
0
        public Request CreateRequest(Request request)
        {
            request.UserId = Guid.Parse(_info.Id);
            request.Date   = DateTime.Now;
            _requestcontext.Requests.Add(request);
            _requestcontext.SaveChanges();

            return(request);
        }
Example #3
0
        public Project CreateProject(Project project)
        {
            project.UserId = Guid.Parse(_info.Id);
            project.Date   = DateTime.Now;
            _projectcontext.Projects.Add(project);
            _projectcontext.SaveChanges();

            return(project);
        }
Example #4
0
        public void Delete(Guid Id)
        {
            var id   = _context.UserRoles.First(x => x.UserId == Id).RoleId;
            var role = _context.Roles.First(x => x.Id == id);

            if (role.Name == "Client")
            {
                _context.Remove(GetById(Id));
                _context.SaveChanges();
            }
        }
Example #5
0
        public async Task <IActionResult> Register(UserRegistration model)
        {
            if (ModelState.IsValid)
            {
                User user = new User {
                    Email = model.Email, UserName = model.Login
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                var profile = new Profile {
                    UserId = user.Id
                };
                _context.Profiles.Add(profile);
                _context.SaveChanges();
                if (!result.Succeeded)
                {
                    return(BadRequest(result.Errors));
                }
                await _userManager.AddToRoleAsync(user, "client");

                return(Created("", "Пользователь успешно создан."));
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }
        }
Example #6
0
 public IActionResult CreateAnnouncemant(Announcemants model, IFormFile file)
 {
     using (FreelanceContext _context = new FreelanceContext())
     {
         string dirpath = Path.GetFullPath("/files/");
         if (!Directory.Exists(dirpath))
         {
             Directory.CreateDirectory(dirpath);
         }
         string path = dirpath + file.FileName;
         using (var stream = System.IO.File.Create(path))
         {
             file.CopyTo(stream);
         }
         model.UserId = _context.Accounts.Single(a => a.Login == User.Identity.Name).Id;
         _context.Announcemants.Add(new Announcemants()
         {
             FullDescription = model.FullDescription,
             MaxWage         = model.MaxWage,
             MinWage         = model.MinWage,
             Title           = model.Title,
             UserId          = model.UserId,
             WageTypeId      = model.WageTypeId,
             Deadline        = model.Deadline,
             PublicDate      = DateTime.Now.Date,
             FilePath        = path,
         });
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
        private void UnsubscribeUser(int userId, string userName)
        {
            using (FreelanceContext context = dataContextFactory.Create())
            {
                if (context.Clients.Any(x => x.Id == userId && x.IsActive == false))
                {
                    return;
                }

                if (!context.Clients.Any(x => x.Id == userId))
                {
                    return;
                }

                Client client = new Client
                {
                    Id       = userId,
                    Name     = userName,
                    IsActive = false
                };

                context.Clients.Update(client);
                context.SaveChanges();
            }
        }
        private void SubscribeUser(int userId, string userName)
        {
            using (FreelanceContext context = dataContextFactory.Create())
            {
                if (context.Clients.Any(x => x.Id == userId && x.IsActive == true))
                {
                    return;
                }

                Client newClient = new Client
                {
                    Id       = userId,
                    Name     = userName,
                    IsActive = true
                };

                bool userExists = context.Clients.Any(x => x.Id == userId);
                if (userExists)
                {
                    context.Clients.Update(newClient);
                }
                else
                {
                    context.Clients.Add(newClient);
                }

                context.SaveChanges();
            }
        }
 protected override void SaveTasks(IEnumerable <FreelanceHuntItem> tasks)
 {
     using (FreelanceContext context = dataContextFactory.Create())
     {
         context.FreelanceHuntItems.AddRange(tasks);
         context.SaveChanges();
     }
 }
Example #10
0
 public IActionResult AddMyBind(Announcemants model, string text)
 {
     using (FreelanceContext _context = new FreelanceContext())
     {
         var userId = _context.Accounts.Single(a => a.Login == User.Identity.Name).Id;
         _context.Binds.Add(new Binds()
         {
             BindText       = text,
             UserId         = userId,
             AnnouncemantId = model.Id
         });
         _context.SaveChanges();
         return(RedirectToAction("Index", "Dashboard"));
     }
 }
Example #11
0
        public async Task Seed()
        {
            string[] roleNames = { "Admin", "Moderator", "Client" };

            foreach (var x in roleNames)
            {
                if (_context.Roles.Where(r => r.Name == x).Count() == 0)
                {
                    await _rolemanager.CreateAsync(new Role { Name = x });
                }
            }
            _context.SaveChanges();

            var  res  = _context.Roles.First(x => x.Name == "Admin");
            User user = new User {
                Email = "*****@*****.**", UserName = "******"
            };
            await _usermanager.CreateAsync(user, "admin123!");

            await _usermanager.AddToRoleAsync(user, "admin");
        }
Example #12
0
 public User CreateUser(User user)
 {
     freelanceContext.Users.Add(user);
     freelanceContext.SaveChanges();
     return(user);
 }
Example #13
0
 public void AddToPool(Payment payment)
 {
     freelanceContext.Payments.Add(payment);
     freelanceContext.SaveChanges();
 }
Example #14
0
 public Offer CreateOffer(Offer offer)
 {
     freelanceContext.Offers.Add(offer);
     freelanceContext.SaveChanges();
     return(offer);
 }
Example #15
0
 public Project CreateProject(Project project)
 {
     freelanceContext.Projects.Add(project);
     freelanceContext.SaveChanges();
     return(project);
 }
Example #16
0
 public Message Create(Message message)
 {
     freelanceContext.Messages.Add(message);
     freelanceContext.SaveChanges();
     return(message);
 }