public async Task ShouldAddApplicationUser()
        {
            userId = await applicationUserService.Add(new ApplicationUser { Username = "******", CredibilityScore = 69, });

            var result = (await applicationUserService.GetByFilter(x => x.Username == "TestUser")).FirstOrDefault();

            Assert.NotNull(result);
        }
Beispiel #2
0
 public HttpResponseMessage Post(HttpRequestMessage request, ApplicationUserViewModel appGroup)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var newAppGroup = new ApplicationUser();
             newAppGroup.UpdateUser(appGroup);
             var result = _appUser.Add(newAppGroup);
             if (result.IsSuccessStatusCode)
             {
                 var newGroup = result.Content.ReadAsAsync <ApplicationUserViewModel>().Result;
                 response = request.CreateResponse(result.StatusCode, newGroup);
             }
             else
             {
                 response = request.CreateErrorResponse(result.StatusCode, result.Content.ReadAsStringAsync().Result);
             }
         }
         return response;
     }));
 }
        public async Task <Guid> AddOrUpdate(VoteViewModel model)
        {
            var userId = (await applicationUserService.GetAsQueriable()).Where(x => x.UserId == model.ApplicationUserId).Select(x => x.Id).FirstOrDefault();

            if (userId == Guid.Empty)
            {
                userId = await applicationUserService.Add(new ApplicationUser
                {
                    UserId           = model.ApplicationUserId,
                    Username         = model.ApplicationUserId,
                    CredibilityScore = 50
                });
            }

            var newsArtileId = (await newsArticleService.GetAsQueriable()).Where(n => n.Source == model.NewsArticleUrl).Select(q => q.Id).FirstOrDefault();

            if (newsArtileId == Guid.Empty)
            {
                throw new Exception("Invalid Article Url");
            }

            var vote = (await GetAsQueriable()).Where(x => x.ApplicationUserId == userId).FirstOrDefault();

            if (vote == null)
            {
                return(await Add(new Vote { ApplicationUserId = userId, NewsArticleId = newsArtileId, IsTrue = model.IsTrue }));
            }
            else
            {
                vote.IsTrue = model.IsTrue;
                return(await Update(vote));
            }
        }
        public ActionResult SaveOrUpdateUser([Bind("Id,FirstName,LastName,UserName,Email,RegistrationDate")] ApplicationUser user)
        {
            try
            {
                if (user != null && user.Id == null)
                {
                    user.RegistrationDate = DateTime.Now;
                    _applicationUserService.Add(user);

                    Alert("Usuário adicionado com sucesso!", Enum.NotificationType.success);
                }
                else
                {
                    _applicationUserService.Update(user);

                    Alert("Usuário atualizado com sucesso!", Enum.NotificationType.success);
                }
            }
            catch (Exception)
            {
                Alert("Informe ao administrador do sistema.", Enum.NotificationType.error);
            }

            ModelState.Clear();
            UpdateUsers(_adminViewModel);

            return(View("User", _adminViewModel));
        }
        public object Save([FromBody] ApplicationUser model)
        {
            try
            {
                if (model.Id != 0)
                {
                    ApplicationUser prevModel = usersService.SingleOrDefault(model.Id, new ApplicationUser());
                    model.UpdatedDate = DateTime.Now;
                    usersService.Update(model);

                    //Insert into audit trial audit and detail

                    //ApplicationUser prevModel = usersService.SingleOrDefault(model.Id, new ApplicationUser());
                    //prevModel.Status = "default";//insert for only audit trail
                    _auditTrailService.InsertUpdatedModelToAuditTrail(model, prevModel, model.UpdatedBy, 7, 4, "Application User", model.Username, "Updated Successfully!");

                    return(model);
                }
                else
                {
                    model = generateSecuredCredentials(model);
                    model = usersService.Add(model);

                    string messagePrefix = ", Your Account Has been Created on OK Wallet Admin Application. Your username is " + model.Username + " and password is " + model.PlainPassword;

                    MessageModel messageModel = new MessageModel()
                    {
                        Mphone      = model.MobileNo,
                        MessageId   = "999",
                        MessageBody = "Dear " + model.Name + messagePrefix + ". Thank you."
                    };

                    MessageService messageService = new MessageService();
                    messageService.SendMessage(messageModel);

                    //Insert into audit trial audit and detail
                    _auditTrailService.InsertModelToAuditTrail(model, model.CreatedBy, 7, 3, "Application User", model.Username, "Saved Successfully!");

                    return(model);
                }
            }
            catch (Exception ex)
            {
                return(errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()));
            }
        }
Beispiel #6
0
 public async Task Post(ApplicationUserViewModel model)
 {
     await ApplicationUserService.Add(model.ToEntity());
 }