public ActionState Update(User entity) { ActionState actionStae = new ActionState(); UserRepository userRepository = new UserRepository(); userRepository.Update(entity, actionStae); return actionStae; }
public ActionState Add(User entity) { ActionState actionStae = new ActionState(); UserRepository userRepository = new UserRepository(); if (userRepository.IsExist(entity, actionStae)) { actionStae.SetFail(ActionStateEnum.AlreadyExist, CommonConstants.IsAlreadyExist); } else { entity.CreatedDate = DateTime.Now; userRepository.Insert(entity, actionStae); } return actionStae; }
public List<TwitterApp.Models.User> FindAll(ActionState actionState) { List<TwitterApp.Models.User> userList; MongoServer server = null; MongoDatabase database = null; TwitterApp.Models.User entity; userList = new List<User>(); entity = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); MongoCollection<BsonDocument> user = database.GetCollection<BsonDocument>(UserConstants.UserCollection); foreach (BsonDocument userEntity in user.FindAll()) { entity = new User(); entity.ID = userEntity[UserConstants.ID].ToString(); entity.Name = userEntity[UserConstants.Name].AsString; entity.Password = userEntity[UserConstants.Password].AsString; entity.CreatedDate = userEntity[UserConstants.CreatedDate].AsDateTime; entity.Username = userEntity[UserConstants.Username].AsString; userList.Add(entity); } actionState.SetSuccess(); } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } return userList; }