public IActionResult Create([FromBody] Profile profile)
        {
            _context.Profiles.Add(profile);
            _context.SaveChanges();

            return(CreatedAtRoute("GetProfile", new { id = profile.Id }, profile));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "FIRSTNAME,LASTNAME,BIRTHDAY,LOCATION,VETSTATUS,OCCUPATION,FAMILY,BIO")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(profile));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,ChatId,Name")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(profile));
        }
Beispiel #4
0
 public void Delete(Profile t)
 {
     try
     {
         _context.Remove(t);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         _logger.LogDebug(e.Message);
     }
 }
        public IActionResult Create([FromBody] Car car)
        {
            if (car == null)
            {
                return(BadRequest());
            }

            _context.Cars.Add(car);
            _context.SaveChanges();

            return(CreatedAtRoute("GetCar", new { id = car.CarId }, car)); // Go to GetCar which is GetById and send the new added car id
        }
Beispiel #6
0
 public void Add(Profile t)
 {
     try
     {
         _context.Profiles.Add(t);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         _logger.LogDebug(e.Message);
     }
 }
Beispiel #7
0
 public IActionResult PostProfile(Profile profile)
 {
     try
     {
         context.Add(profile);
         context.SaveChanges();
     }
     catch (DbUpdateException)
     {
         return(BadRequest("Id already in use"));
     }
     return(NoContent());
 }
Beispiel #8
0
        public void UpdateProfile_Return_True()
        {
            //Arrange
            var options = GetContextOptions();

            var newProfile = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = "BankBook",
                FirstName  = "FirstName",
                LastName   = "LastName",
                SecondName = "SecondName",
                Passport   = "Passport",
                OrgName    = "OrgName",
                IsSeller   = false,
                OrgNumber  = "OrgNumber"
            };

            ProfileModel oldProfile;
            ProfileModel updatedProfile;

            var result = false;

            //Act
            using (var context = new ProfileContext(options))
            {
                context.Profiles.Add(newProfile);
                context.SaveChanges();

                oldProfile                = context.Profiles.AsNoTracking().LastOrDefault();
                updatedProfile            = context.Profiles.LastOrDefault();
                updatedProfile.Balance    = 2;
                updatedProfile.BankBook   = Guid.NewGuid().ToString();
                updatedProfile.FirstName  = Guid.NewGuid().ToString();
                updatedProfile.IsSeller   = true;
                updatedProfile.LastName   = Guid.NewGuid().ToString();
                updatedProfile.SecondName = Guid.NewGuid().ToString();
                updatedProfile.Passport   = Guid.NewGuid().ToString();
                updatedProfile.OrgName    = Guid.NewGuid().ToString();
                updatedProfile.OrgNumber  = Guid.NewGuid().ToString();

                var updatedProfileViewModel = _mapper.Map <ProfileViewModel>(updatedProfile);

                IProfileService profileService = new ProfileService(context, _mapper, _rabbitMQService.Object, _scopeFactory);
                result = profileService.UpdateProfileAsync(updatedProfileViewModel).GetAwaiter().GetResult();

                updatedProfile = context.Profiles.LastOrDefault();
            }

            //Assert
            Assert.True(result);
            Assert.NotEqual(oldProfile.Balance, updatedProfile.Balance);
            Assert.NotEqual(oldProfile.BankBook, updatedProfile.BankBook);
            Assert.NotEqual(oldProfile.FirstName, updatedProfile.FirstName);
            Assert.NotEqual(oldProfile.SecondName, updatedProfile.SecondName);
            Assert.NotEqual(oldProfile.LastName, updatedProfile.LastName);
            Assert.NotEqual(oldProfile.OrgName, updatedProfile.OrgName);
            Assert.NotEqual(oldProfile.OrgNumber, updatedProfile.OrgNumber);
            Assert.NotEqual(oldProfile.IsSeller, updatedProfile.IsSeller);
        }
Beispiel #9
0
        public ActionResult Create([Bind(Exclude = "USERID", Include = "FIRSTNAME,LASTNAME,BIRTHDAY,CITY,STATE,VETSTATUS,OCCUPATION,FAMILY,BIO")] Profile profile)
        {
            ModelState.Remove("USERID");                                   // user doesn't input a key so we need to get the key of the current user logged in who created the profile.
            profile.USERID = User.Identity.GetUserId();                    //get user id of current user
            var      errors = ModelState.Values.SelectMany(v => v.Errors); // debugging for errors
            DateTime currentTime, userbirthday = new DateTime();

            currentTime = DateTime.Now;                                    //get the current date
            currentTime = currentTime.AddYears(-65);                       // -65 years to determine if the user meets our standards.
            var    data           = ViewData.ModelState["BIRTHDAY"].Value; // get model data
            string BirthdayString = data.AttemptedValue;                   //get string date from data, must be converted to datetime for comparison.


            string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss",
                                            "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss,fff" };                         //Accepted user input formats

            CultureInfo provider = new CultureInfo("en-US");                                                            //US time standard

            if (!DateTime.TryParseExact(BirthdayString, validformats, provider, DateTimeStyles.None, out userbirthday)) //attempt to convert, check to see if it fails
            {
                ModelState.AddModelError("BIRTHDAY", "Invalid Formatting, try something like this 01/23/1932");         //if failed inform of invalid format
            }

            else if (userbirthday >= currentTime) // dont continueif failed, check if user is old enough to register, return an error if they are not
            {
                ModelState.AddModelError("BIRTHDAY", "I'm sorry, but you must be 65 Years or older to make a profile");
            }


            if (ModelState.IsValid)
            {
                profile.BIRTHDAY       = userbirthday; //Correct formatting for DB
                profile.PROFILECREATED = true;         //user created profile
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(RedirectToAction("Create", "HobbyBridges")); //edit this line maddy
            }

            return(View(profile));
        }
 public bool Register(Profile t)
 {
     try
     {
         _context.Profiles.Add(t);
         _context.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(false);
 }
        public object Post([FromBody] LoginData obj)
        {
            var        isAvaluable = _profileContext.loginData.FirstOrDefault(row => obj.Email == row.Email);
            ReturnData returnData  = new ReturnData();

            if (isAvaluable != null && obj.Name == null)
            {
                if (isAvaluable.Password == obj.Password)
                {
                    returnData.OutPut  = true;
                    returnData.message = "Login succefully";
                    return(returnData);
                }
                else
                {
                    returnData.OutPut  = false;
                    returnData.message = "Incorrect password";
                    return(returnData);
                }
            }
            if (isAvaluable == null && obj.Surname != null)
            {
                _profileContext.loginData.Add(obj);
                _profileContext.SaveChanges();
                returnData.OutPut  = true;
                returnData.message = "Register successfully";
                return(returnData);
            }
            else if (isAvaluable != null && obj.Surname != null)
            {
                returnData.OutPut  = false;
                returnData.message = "Email already exist";
                return(returnData);
            }
            returnData.OutPut  = false;
            returnData.message = "Email does not exist";
            return(returnData);
        }
Beispiel #12
0
        public void AddNewProfile_Return_IdAndFalse()
        {
            //Arrange
            var options = GetContextOptions();

            var profileModel = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = "Passport",
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            var profileViewModel = new ProfileViewModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = "Passport",
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            var result  = string.Empty;
            var success = false;

            //Act
            using (var context = new ProfileContext(options))
            {
                context.Profiles.Add(profileModel);
                context.SaveChanges();

                IProfileService profileService = new ProfileService(context, _mapper, _rabbitMQService.Object, _scopeFactory);
                (result, success) = profileService.AddNewProfileAsync(profileViewModel).GetAwaiter().GetResult();
            }

            //Assert
            Assert.False(success);
            Assert.Equal(GlobalConstants.PROFILE_SERVICE_FAIL, result);
        }
Beispiel #13
0
 public void SaveSuggestion(string sender, string userName, string body)
 {
     using (ProfileContext db = new ProfileContext())
     {
         db.UserSuggestions.Add(
             new UserSuggestion()
         {
             Datetime = DateTime.Now,
             Email    = sender,
             UserName = userName,
             Body     = body
         }
             );
         db.SaveChanges();
     }
 }
Beispiel #14
0
 public void SaveEmail(string sender, string userName, string subject, string body)
 {
     using (ProfileContext db = new ProfileContext())
     {
         db.Mails.Add(
             new Mail()
         {
             Datetime = DateTime.Now,
             Email    = sender,
             Subject  = subject,
             UserName = userName,
             Body     = body
         }
             );
         db.SaveChanges();
     }
 }
Beispiel #15
0
        public IActionResult Create([FromBody] Comment comment)
        {
            if (comment == null)
            {
                return(BadRequest());
            }

            _context.Comments.Add(comment); // Add comment to DB

            // ** Adding comment to car by id — Does not work proberly ** //
            var car = _context.Cars.Single(x => x.CarId == comment.CarId);

            car.Comments.Add(comment);
            _context.Cars.Update(car);

            _context.SaveChanges();

            return(CreatedAtRoute("GetComment", new { id = comment.CommentId }, comment)); // Go to GetComment which is GetById
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (ProfileContext db = new ProfileContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Beispiel #17
0
        public void GetProfileById_Return_Profile()
        {
            //Arrange
            var options         = GetContextOptions();
            var expectedProfile = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = Guid.NewGuid().ToString(),
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            ProfileViewModel actualProfile;

            //Act
            using (var context = new ProfileContext(options))
            {
                context.Profiles.Add(expectedProfile);
                context.SaveChanges();

                IProfileService profileService = new ProfileService(context, _mapper, _rabbitMQService.Object, _scopeFactory);
                actualProfile = profileService.GetProfileByIdAsync(expectedProfile.Id).GetAwaiter().GetResult();
            }

            //Assert
            Assert.Equal(expectedProfile.Id, actualProfile.Id);
            Assert.Equal(expectedProfile.IsSeller, actualProfile.IsSeller);
            Assert.Equal(expectedProfile.LastName, actualProfile.LastName);
            Assert.Equal(expectedProfile.FirstName, actualProfile.FirstName);
            Assert.Equal(expectedProfile.SecondName, actualProfile.SecondName);
            Assert.Equal(expectedProfile.OrgName, actualProfile.OrgName);
            Assert.Equal(expectedProfile.OrgNumber, actualProfile.OrgNumber);
            Assert.Equal(expectedProfile.Balance, actualProfile.Balance);
            Assert.Equal(expectedProfile.BankBook, actualProfile.BankBook);
        }
Beispiel #18
0
        // GET: /Profile/
        public ActionResult Index()
        {
            var currentUser = UserDB.Users.Find(User.Identity.GetUserId());

            if (currentUser.MadeProfileYet)
            {
                var vm = new ProfileStatusVM();
                vm.StatusList = new List <Status>();

                Guid UserId  = new Guid(User.Identity.GetUserId());
                var  profile = db.Profile.FirstOrDefault(x => x.AspNetUser_Id == UserId);
                vm.Profile = profile;
                var listOfAllStatuses = db.Status.ToList();
                var listOfUserStatus  = (from x in listOfAllStatuses
                                         where x.UserWhomStatusBelongsTo == profile.Id
                                         select x).ToList();

                foreach (var entry in listOfUserStatus)
                {
                    vm.StatusList.Add(entry);
                }
                if (vm.StatusList.Count == 0)
                {
                    Status firstStatus = new Status();
                    firstStatus.StatusUpdate            = "Welcome!";
                    firstStatus.TimeOfUpdate            = DateTime.Now;
                    firstStatus.UserWhomStatusBelongsTo = profile.Id;
                    firstStatus.UpdatedByFullName       = "Admin";
                    db.Status.Add(firstStatus);
                    vm.StatusList.Add(firstStatus);
                    db.SaveChanges();
                    //vm.StatusList.Add(new Status { StatusUpdate = "Welcome!", UserWhomStatusBelongsTo = profile.Id, UpdatedByFullName = profile.FullName, TimeOfUpdate = DateTime.Now });
                }

                return(View(vm));
            }
            else
            {
                return(RedirectToAction("MakeProfile"));
            }
        }
Beispiel #19
0
 public void SaveNewProfile(Profile profile)
 {
     _profileContext.Add(profile);
     _profileContext.SaveChanges();
 }
Beispiel #20
0
 public void Save(T obj)
 {
     _context.Add(obj);
     _context.SaveChanges();
 }
Beispiel #21
0
 public IActionResult Create(Profile item)
 {
     _context.ProfileItems.Add(item);
     _context.SaveChanges();
     return(CreatedAtRoute("getProfile", new { id = item.Id }, item));
 }
Beispiel #22
0
 public int Create(Team team)
 {
     _context.Teams.Add(team);
     return(_context.SaveChanges());
 }
 public async Task SaveChangeAsync()
 {
     _db.SaveChanges();
 }
Beispiel #24
0
        public ProfilesController(ProfileContext context)
        {
            _context = context;

            if (_context.ProfileItems.Count() == 0)
            {
                _context.ProfileItems.Add(new Profile {
                    Id            = 1,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Stephen Sladek",
                    Major         = "Information Systems",
                    Location      = "Gordonville, MO",
                    CollegeStatus = "Senior",
                    Languages     = "C, C++, C#, Java, JavaScript",
                    Interests     = "Virtual Reality, Biometrics",
                    Organizations = "ACM-SEMO, CS Club, SIGAI"
                });
                _context.ProfileItems.Add(new Profile  {
                    Id            = 2,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "Cybersecurity",
                    Location      = "---",
                    CollegeStatus = "Freshman",
                    Languages     = "---",
                    Interests     = "---",
                    Organizations = "---"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 3,
                    ImgPath       = "../../assets/images/Derek_Mandl.jpg",
                    Name          = "Derek Mandl",
                    Major         = "Computer Science",
                    Location      = "Manchester, MO",
                    CollegeStatus = "Senior",
                    Languages     = "C, C++, Java, Python",
                    Interests     = "Compilers, Image Processing",
                    Organizations = "ACM-SEMO, Camera Arts Association"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 4,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "Computer Science",
                    Location      = "---",
                    CollegeStatus = "Junior",
                    Languages     = "Java,Python,SQL",
                    Interests     = "none",
                    Organizations = "none"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 5,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "---",
                    Location      = "---",
                    CollegeStatus = "---",
                    Languages     = "---",
                    Interests     = "---",
                    Organizations = "---"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 6,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "---",
                    Location      = "---",
                    CollegeStatus = "---",
                    Languages     = "---",
                    Interests     = "---",
                    Organizations = "---"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 7,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "---",
                    Location      = "---",
                    CollegeStatus = "---",
                    Languages     = "---",
                    Interests     = "---",
                    Organizations = "---"
                });
                _context.ProfileItems.Add(new Profile {
                    Id            = 8,
                    ImgPath       = "../../assets/images/anon.jpg",
                    Name          = "Anonymous",
                    Major         = "---",
                    Location      = "---",
                    CollegeStatus = "---",
                    Languages     = "---",
                    Interests     = "---",
                    Organizations = "---"
                });

                _context.SaveChanges();
            }
        }
Beispiel #25
0
 public void Create(Profile item)
 {
     context.ProfilesItems.Add(item);
     context.SaveChanges();
 }
Beispiel #26
0
        public void GetAllProfiles_Return_Profiles()
        {
            //Arrange
            var options = GetContextOptions();

            #region New profiles

            var profileOne = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = Guid.NewGuid().ToString(),
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            var profileTwo = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = Guid.NewGuid().ToString(),
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            var profileThree = new ProfileModel()
            {
                Balance    = 1,
                BankBook   = Guid.NewGuid().ToString(),
                FirstName  = Guid.NewGuid().ToString(),
                LastName   = Guid.NewGuid().ToString(),
                SecondName = Guid.NewGuid().ToString(),
                Passport   = Guid.NewGuid().ToString(),
                OrgName    = Guid.NewGuid().ToString(),
                IsSeller   = false,
                OrgNumber  = Guid.NewGuid().ToString()
            };

            #endregion New profiles

            List <ProfileViewModel> actualProfiles;

            //Act
            using (var context = new ProfileContext(options))
            {
                context.Profiles.Add(profileOne);
                context.Profiles.Add(profileTwo);
                context.Profiles.Add(profileThree);
                context.SaveChanges();

                IProfileService profileService = new ProfileService(context, _mapper, _rabbitMQService.Object, _scopeFactory);

                actualProfiles = profileService.GetAllProfilesAsync().GetAwaiter().GetResult().ToList();
            }

            //Assert
            Assert.Equal(3, actualProfiles.Count);
        }
 /// <summary>
 /// Returns bool if there was an item changed
 /// </summary>
 /// <returns>Bool</returns>
 public bool Save()
 {
     return(_profileContext.SaveChanges() >= 0);
 }
Beispiel #28
0
 public int Create(Employee employee)
 {
     employee.RemainingDay = 12;
     _profileContext.Add(employee);
     return(_profileContext.SaveChanges());
 }
Beispiel #29
0
 public void CreateProfile(Profile profile)
 {
     _dbContext.Profiles.Add(profile);
     _dbContext.SaveChanges();
 }