Beispiel #1
0
        public async Task<Response<OperationResult>> CreateUser(UserCreationRequest model)
        {
            var responce = new Response<OperationResult>
            {
                Data = OperationResult.Failed
            };

            if (model == null)
            {
                return responce;
            }

            var entity = new UserEntity(model);

            var isExist = _context.Users.Any(x => x.Login.Equals(entity.Login, StringComparison.OrdinalIgnoreCase) || x.Email.Equals(entity.Email, StringComparison.OrdinalIgnoreCase));

            if (isExist)
            {
                responce.Error = new Error("User info is created!");
                return responce;
            }

            await _context.Users.AddAsync(entity);
            await _context.SaveChangesAsync();

            responce.Data = OperationResult.Success;
            return responce;
        }
        public async Task <IActionResult> PutHouse(long id, House house)
        {
            if (id != house.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutApartment(long id, Apartment apartment)
        {
            if (id != apartment.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #4
0
 public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Author,Genre,URL,Album")] Song song)
 {
     if (id != song.ID)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(song);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!SongExists(song.ID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(song));
 }
Beispiel #5
0
        public async Task <IActionResult> CreazaPacient(CreatePacientRequest request)
        {
            await context.Medic.Where(m => m.CodParafa == request.MedicId).LoadAsync();

            Medic medic = await context.Medic.Where(m => m.CodParafa == request.MedicId).Include(m => m.Pacients).FirstOrDefaultAsync();

            if (medic == null)
            {
                return(BadRequest());
            }

            medic.Pacients.Add(new Pacient()
            {
                Nume       = request.Nume,
                Prenume    = request.Prenume,
                PacientCNP = request.PacientCNP,
                Profesie   = request.Profesie,
                Sex        = request.Sex,
                Telefon    = request.Telefon,
                Varsta     = request.Varsta,
                Email      = request.Email,
                LocDeMunca = request.LocDeMunca,
                MedicId    = medic.MedicId
            });


            await context.SaveChangesAsync();

            return(Ok("Pacientul a fost adaugat"));
        }
        public async Task <IActionResult> Create([Bind("id,name")] Developer developer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(developer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(developer));
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("id,name,mail,password,shoppingCartId")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("FlowerID,FlowerName")] Flower flower)
        {
            if (ModelState.IsValid)
            {
                _context.Add(flower);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(flower));
        }
        public async Task <IActionResult> Create([Bind("CustomerID,LastName,FirstMidName,RegistrationDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("id,userId")] ShoppingCart shoppingCart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingCart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["userId"] = new SelectList(_context.User, "id", "id", shoppingCart.userId);
            return(View(shoppingCart));
        }
        public async Task <IActionResult> Create([Bind("id,text,score,gameId")] Review review)
        {
            if (ModelState.IsValid)
            {
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["gameId"] = new SelectList(_context.Games, "id", "id", review.gameId);
            return(View(review));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Region Region)
        {
            if (ModelState.IsValid)
            {
                Region.Active = 1;
                _context.Add(Region);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Region));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("Id,Name,RegionId")] Country country)
        {
            if (ModelState.IsValid)
            {
                country.Active = 1;
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RegionId"] = new SelectList(_context.Region, "Id", "Id", country.RegionId);
            return(View(country));
        }
Beispiel #14
0
        public async Task <IActionResult> Create([Bind("Id,Name,CountryId, JenkisAddress, GitAddress, ProvisionGitAddress, NexusFrontEndAddress, NexusProductAddress, BiometricProductAddress, Notes")] Project project)
        {
            if (ModelState.IsValid)
            {
                project.Active = 1;
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Id", project.CountryId);
            return(View(project));
        }
        public async Task <IActionResult> Create([Bind("OrderID,CustomerID,FlowerID")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "CustomerID", order.CustomerID);
            ViewData["FlowerID"]   = new SelectList(_context.Flowers, "FlowerID", "FlowerID", order.FlowerID);
            return(View(order));
        }
Beispiel #16
0
        public async Task <Response <OperationResult> > Create(string userId, FollowingRequest model)
        {
            var responce = new Response <OperationResult>();

            var entity = new ComunityEntity(userId, model);

            await _context.Comunities.AddAsync(entity);

            await _context.SaveChangesAsync();

            responce.Data = OperationResult.Success;
            return(responce);
        }
        public async Task <IActionResult> Create([Bind("id,name,description,imageUrl,price,developerId,publisherId")] Game game)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["developerId"] = new SelectList(_context.Developer, "id", "id", game.developerId);
            ViewData["publisherId"] = new SelectList(_context.Publisher, "id", "id", game.publisherId);
            return(View(game));
        }
Beispiel #18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CountryId")] Project project)
        {
            if (id != project.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(project);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectExists(project.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Id", project.CountryId);
            return(View(project));
        }
Beispiel #19
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Name == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Name = model.Email, Password = model.Password
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(model.Email); // аутентификация

                    return(RedirectToAction("Index", "Main"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Beispiel #20
0
 public void Atualizar(T Objeto)
 {
     using (var banco = new GeneralContext(_OptionsBuilder))
     {
         banco.Set <T>().Update(Objeto);
         banco.SaveChangesAsync();
     }
 }
Beispiel #21
0
 public void Excluir(T Objeto)
 {
     using (var banco = new GeneralContext(_OptionsBuilder))
     {
         banco.Set <T>().Remove(Objeto);
         banco.SaveChangesAsync();
     }
 }
Beispiel #22
0
 public async Task RemoveByUserAsync(ulong userId)
 {
     using (GeneralContext database = new GeneralContext())
     {
         database.Reminder.RemoveRange(database.Reminder.Where(x => x.UserId.Equals(userId)));
         await database.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Beispiel #23
0
        public async Task <Response <LikeAction> > CreateLike(string postId, string userLikeFromId)
        {
            var responce = new Response <LikeAction>();

            var likeInfo = await _context.Likes.Include(x => x.LikeBindings).FirstOrDefaultAsync(x => x.ModuleId == postId);

            if (likeInfo == null)
            {
                responce.Error = new Error("Can`t find post by id");
                return(responce);
            }

            var isLikeExistFromUser = likeInfo.LikeBindings.Any(x => x.UserId == userLikeFromId);

            if (isLikeExistFromUser)
            {
                var like = likeInfo.LikeBindings.FirstOrDefault(x => x.UserId == userLikeFromId);

                _context.LikeBindings.Remove(like);
                await _context.SaveChangesAsync();

                likeInfo.LikeBindings.Remove(like);
                likeInfo.CountOfLikes--;
                _context.Likes.Update(likeInfo);
                await _context.SaveChangesAsync();

                responce.Data = LikeAction.LikeRemoved;
                return(responce);
            }
            else
            {
                var like = new LikeBinding(userLikeFromId, likeInfo.Id);
                await _context.LikeBindings.AddAsync(like);

                await _context.SaveChangesAsync();

                likeInfo.LikeBindings.Add(like);
                likeInfo.CountOfLikes++;
                _context.Likes.Update(likeInfo);
                await _context.SaveChangesAsync();


                responce.Data = LikeAction.LikeAdded;
                return(responce);
            }
        }
Beispiel #24
0
 public void Adcionar(T Objeto)
 {
     using (var banco = new GeneralContext(_OptionsBuilder))
     {
         banco.Set <T>().Add(Objeto);
         banco.SaveChangesAsync();
     }
 }
        public async Task <IActionResult> PostUserPreferences([FromBody] UserPreferences userPreferences)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                _context.UserPreference.Add(userPreferences);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetUserPreferences", new { id = userPreferences.UserID }, userPreferences));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Beispiel #26
0
        public async Task <bool> CreazaLogin(String username, String parola)
        {
            User user = await context.User.Where(u => u.Username.Equals(username)).FirstOrDefaultAsync();

            if (user != null)
            {
                return(false);
            }
            user = new User()
            {
                Username = username,
                Password = parola
            };
            context.User.Add(user);
            await context.SaveChangesAsync();

            return(true);
        }
Beispiel #27
0
        public async Task <Response <OperationResult> > CreatePost(PostDTO model)
        {
            var responce = new Response <OperationResult>();

            var entity = new PostEntity(model);

            await _context.Posts.AddAsync(entity);

            await _context.SaveChangesAsync();

            var likeInfo = new LikeEntity <PostEntity> {
                ModuleId = entity.Id
            };
            await _context.Likes.AddAsync(likeInfo);

            await _context.SaveChangesAsync();

            responce.Data = OperationResult.Success;
            return(responce);
        }
Beispiel #28
0
        public async Task <bool> SaveMessageAsync(MessageDTO message)
        {
            var userFrom = await _context.Users.FirstOrDefaultAsync(x => x.Id == message.UserIdFrom);

            var userTo = await _context.Users.FirstOrDefaultAsync(x => x.Id == message.UserIdTo);

            var room = await _context.ChatRooms.FirstOrDefaultAsync(x => x.Id == message.RoomId);

            if (userFrom == null || userTo == null)
            {
                throw new NullReferenceException();
            }

            if (room == null)
            {
                var roomEntity = new RoomEntity(userFrom, userTo, message.Data);
                await _context.ChatRooms.AddAsync(roomEntity);

                await _context.SaveChangesAsync();
            }

            if (room != null)
            {
                if (room.UserFrom.Id != userFrom.Id || room.UserTo.Id != userTo.Id)
                {
                    throw new NullReferenceException();
                }
            }

            var messageEntity = new MessageEntity(message.Data, message.Time, room);

            await _context.Messages.AddAsync(messageEntity);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> CreateMedic(CreateMedicRequest request)
        {
            if (await context.Medic.Where(m => m.CodParafa == request.CodParafa).AnyAsync())
            {
                return(BadRequest("Exista deja un medic cu acest cod parafa"));
            }
            Medic medic = new Medic()
            {
                Nume      = request.Nume,
                Prenume   = request.Prenume,
                CodParafa = request.CodParafa,
                Parola    = request.Parola
            };

            context.Medic.Add(medic);
            //Creaza login pentru medic(folosit pentru token)
            if (!await CreazaLogin(request.CodParafa.ToString(), request.Parola))
            {
                return(BadRequest("Nu sa putut inregistra autentificarea! Exista deja un user cu acest username(cod parafa)!"));
            }
            await context.SaveChangesAsync();

            return(Ok("Medicul a fost inregistrat"));
        }
        public async Task <IActionResult> TestTratament()
        {
            await context.Pacient.Where(p => p.PacientCNP == 13213141).Include(p => p.Tratamente).FirstOrDefaultAsync();

            Pacient   pacient   = context.Pacient.Where(p => p.PacientCNP == 13213141).FirstOrDefault();
            Tratament tratament = new Tratament()
            {
                Diagnostic = "s",
                Medicament = "s",
                Pat        = 1,
            };

            pacient.Tratamente.Add(tratament);
            await context.SaveChangesAsync();

            return(Ok());
        }