public void Should_UpdateData()
        {
            IRepository <User> repository = StartRepository();;

            Assert.IsNotNull(repository);

            User testUser1 = new User
            {
                Id       = Guid.NewGuid(),
                Password = "******",
                Profile  = "testProfile",
                Username = "******"
            };

            repository.Insert(testUser1);

            User testExistingUser = repository.GetSingle(x => x.Id == testUser1.Id);

            Assert.NotNull(testExistingUser);

            string newProfile = "New Profile Description";

            testExistingUser.Profile = newProfile;

            repository.Update(testExistingUser);
            User updatedUser = repository.GetSingle(x => x.Id == testUser1.Id);

            Assert.NotNull(updatedUser);
            Assert.AreEqual(testUser1.Id, updatedUser.Id);
            Assert.AreEqual(newProfile, updatedUser.Profile);

            repository.Delete(x => x.Id == testExistingUser.Id);
        }
Esempio n. 2
0
 public User GetBySessionID(string guid)
 {
     return(_repository.GetSingle <User>(u =>
                                         u.active &&
                                         u.Session.Any(s => s.active && s.guid == guid)
                                         ));
 }
        public string EditRoles(
            Guid id,
            string title
            )
        {
            var obj = _role.GetAll()
                      .Where(x => x.Title == title)
                      .FirstOrDefault();

            if (obj != null)
            {
                return(FormatUtil.Result(0, "该已存该角色", 1, ""));
            }
            var singleone = _role.GetSingle(id);

            singleone.Title       = title;
            singleone.Update_time = DateTime.Now;
            int statu = _role.EditAndSave(singleone);

            if (statu != 1)
            {
                return(FormatUtil.Result(0, "编辑失败,稍后重试", 1, ""));
            }
            else
            {
                return(FormatUtil.Result(0, "编辑成功", 0, ""));
            }
        }
        public void Should_DeleteData()
        {
            IRepository <User> repository = StartRepository();

            Assert.IsNotNull(repository);

            User testUser1 = new User
            {
                Id       = Guid.NewGuid(),
                Password = "******",
                Profile  = "testProfile",
                Username = "******"
            };

            repository.Insert(testUser1);

            User existingUser = repository.GetSingle(x => x.Id == testUser1.Id);

            Assert.NotNull(existingUser);

            repository.Delete(x => x.Id == testUser1.Id);
            User shouldNotExist = repository.GetSingle(x => x.Id == testUser1.Id);

            Assert.IsNull(shouldNotExist);
        }
Esempio n. 5
0
        public JsonResult GetStudentInfo(int id)
        {
            var student   = _repository.GetSingle <User>(s => s.Id == id);
            var uug       = _repository.Get <UserToUserGroup>(ug => ug.UserId == id);
            var usergroup = _repository.Get <UserGroup>();

            var query = from g in usergroup
                        join ug in uug on g.Id equals ug.GroupId
                        where ug.UserId == id
                        select g;

            var gr = new List <object>();

            foreach (var item in query)
            {
                gr.Add(item.Name);
            }


            var data = new
            {
                id         = student.Id,
                firstName  = student.FirstName,
                lastName   = student.LastName,
                fatherName = student.FatheName,
                phone      = student.Phone,
                email      = student.Email,
                userGroup  = gr
            };

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public static VendorAssortment GetMatchedVendorAssortment(IRepository <VendorAssortment> repo, int vendorID, int productID, bool onlyActive = true)
        {
            VendorAssortment va = null;

            using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
            {
                var funcRepo = ((IFunctionScope)unit.Scope).Repository();
                if (onlyActive)
                {
                    va = repo.GetSingle(x => (x.VendorID == vendorID || (x.Vendor.ParentVendorID.HasValue && x.Vendor.ParentVendorID.Value == vendorID)) && x.ProductID == productID && x.IsActive);
                }
                else
                {
                    va = repo.GetSingle(x => (x.VendorID == vendorID || (x.Vendor.ParentVendorID.HasValue && x.Vendor.ParentVendorID.Value == vendorID)) && x.ProductID == productID);
                }

                if (va == null)
                {
                    var matches = funcRepo.FetchProductMatches(productID, vendorID).ToList();

                    if (matches.Count > 0)
                    {
                        int matchProductID = matches.FirstOrDefault().ProductID;

                        Product prod = unit.Scope.Repository <Product>().GetSingle(c => c.ProductID == matchProductID);
                        va = prod.VendorAssortments.FirstOrDefault(x => x.VendorID == vendorID || (x.Vendor.ParentVendorID.HasValue && x.Vendor.ParentVendorID.Value == vendorID));
                    }
                }
                return(va);
            }
        }
Esempio n. 7
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var user    = GetCurrentUserAsync().Result;
            var profile = _profileRepo.GetSingle(p => p.UserId == user.Id);

            if (profile == null)
            {
                profile = new Profile()
                {
                    DisplayName      = "",
                    Firstname        = "",
                    Lastname         = "",
                    Phone            = "",
                    DisplayPhotoPath = "images/user.png",
                    UserId           = user.Id
                };

                _profileRepo.Create(profile);
            }

            ProfileIndexViewModel vm = new ProfileIndexViewModel()
            {
                DisplayName      = profile.DisplayName,
                Firstname        = profile.Firstname,
                Lastname         = profile.Lastname,
                Phone            = profile.Phone,
                DisplayPhotoPath = profile.DisplayPhotoPath
            };

            return(View(vm));
        }
Esempio n. 8
0
        public int RemoveHeadsFromProject(Project project, IList <Head> heads)
        {
            int    count     = 0;
            string headNames = "";

            foreach (Head deletableHead in heads)
            {
                ProjectHead deletableProjectHead = _projectHeadRepository.GetSingle(ph => ph.Project.ID == project.ID && ph.Head.ID == deletableHead.ID);
                if (deletableProjectHead != null)
                {
                    headNames += string.IsNullOrWhiteSpace(headNames) ? deletableHead.Name : ", " + deletableHead.Name;
                }
                project.ProjectHeads.Remove(deletableProjectHead);
            }
            count = _projectHeadRepository.Save();

            if (count > 0)
            {
                InvokeManagerEvent(EventType.Success, "", string.Concat("Head(s) removed from project '", project.Name, "': ", headNames, "."));
            }
            else
            {
                InvokeManagerEvent(EventType.Information, "", string.Concat("No head(s) removed from project '", project.Name, "'."));
            }
            return(count);
        }
Esempio n. 9
0
        public async Task <IActionResult> Index()
        {
            var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

            ProviderProfile loggedProfile = _profileRepo.GetSingle(p => p.UserId == loggedUser.Id);

            if (loggedProfile == null)
            {
                return(RedirectToAction("UpdateProfile"));
            }

            DisplayProviderProfileViewModel vm = new DisplayProviderProfileViewModel
            {
                UserId           = loggedUser.Id,
                UserName         = loggedUser.UserName,
                activePackages   = _packRepo.Query(p => p.UserId == loggedUser.Id && p.IsActive == true),
                inactivePackages = _packRepo.Query(p => p.UserId == loggedUser.Id && p.IsActive == false),
            };

            if (loggedProfile.ImgPath == null)
            {
                vm.ImgPath = "admin\\person-solid.png";
            }
            else
            {
                vm.ImgPath = loggedProfile.ImgPath;
            }


            return(View(vm));
        }
Esempio n. 10
0
        private string GetOrganization(WorkItemViewModel item)
        {
            var project      = _repository.GetSingle <Project>(p => p.Name == GetProject(item));
            var organization = project != null?_repository.GetSingle <VstsOrganization>(o => o.Id == project.Organization) : null;

            return(organization != null ? organization.Name : string.Empty);
        }
        public MyTask GetSingle(int id)
        {
            MyTask task = _repo.GetSingle(x => x.Id == id);

            task.TaskDateString = task.TaskDate.ToString();
            return(task);
        }
Esempio n. 12
0
        public async Task <List <Responses.Watcher> > GetAllWatchers(string userId = null, string currencyId = null, string indicatorId = null)
        {
            // Get user
            var user = await _userRepository.GetSingle(userId);

            // Check if it exists
            if (user == null)
            {
                throw new NotFoundException(UserMessage.UserNotFound);
            }

            // Get all watchers
            var userWatchers = await _watcherRepository.GetAll(WatcherExpression.WatcherFilter(userId, currencyId, indicatorId));

            // Get all default watchers
            var defaultWatchers = await _watcherRepository.GetAll(WatcherExpression.DefaultWatcher(currencyId, indicatorId));

            // Build with defaults
            userWatchers = WatcherBuilder.BuildWatchersWithDefaults(userWatchers, defaultWatchers);

            // Response
            var response = _mapper.Map <List <Responses.Watcher> >(userWatchers);

            // Return
            return(response);
        }
Esempio n. 13
0
        public void Employee_Repo_Get_By_Id()
        {
            var actual = _repo.GetSingle(e => e.EmployeeId.Equals(1));

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.EmployeeId);
            Assert.AreEqual(1, actual.BusinessUnit.BusinessUnitId);
        }
        public void Delete(int id)
        {
            var entity = _yetkiRepository.GetSingle(x => x.Id == id && !x.Silindi);

            entity.Silindi     = true;
            entity.EntityState = EntityState.Modified;
            _yetkiRepository.Save(entity);
        }
Esempio n. 15
0
        public bool Add(Project project)
        {
            if (ProjectWithSameNameAlreadyExists(project))
            {
                return(false);
            }

            _projectRepository.Insert(project);
            Head cashBook = _headRepository.GetSingle(h => h.Name == "Cash Book");
            Head bankBook = _headRepository.GetSingle(h => h.Name == "Bank Book");

            _projectHeadRepository.Insert(new ProjectHead()
            {
                Project = project, Head = cashBook, IsActive = true
            });
            _projectHeadRepository.Insert(new ProjectHead()
            {
                Project = project, Head = bankBook, IsActive = true
            });

            if (_projectRepository.Save() > 0)
            {
                InvokeManagerEvent(new BLLEventArgs {
                    EventType = EventType.Success, MessageKey = "NewProjectSuccessfullyCreated", Parameters = new Dictionary <string, string> {
                        { "ProjectName", project.Name }
                    }
                });

                if (_headRepository.GetSingle(h => h.Name == project.Name) == null)
                {
                    Head newHead = new Head
                    {
                        Name        = project.Name,
                        IsActive    = true,
                        HeadType    = "Capital",
                        Description =
                            "This head (related with project '" + project.Name +
                            "') is only for inter project loan."
                    };
                    _headRepository.Insert(newHead);
                    if (_headRepository.Save() > 0)
                    {
                        InvokeManagerEvent(new BLLEventArgs {
                            EventType = EventType.Success, MessageDescription = "A head with name '" + project.Name + "' is created for inter project loan."
                        });
                    }
                }
                else
                {
                    InvokeManagerEvent(new BLLEventArgs {
                        EventType = EventType.Success, MessageDescription = "Same head with name '" + project.Name + "' already found."
                    });
                }
                return(true);
            }
            return(false);
        }
        public void Delete(int id)
        {
            var entity = _girisRepository.GetSingle(x => x.Id == id && !x.Deleted);

            entity.Deleted     = true;
            entity.Actived     = false;
            entity.EntityState = EntityState.Modified;
            _girisRepository.Save(entity);
        }
Esempio n. 17
0
        public async Task AddMember(ProjectMemberDto dto)
        {
            Project project = await m_projectRepository.GetSingle(dto.ProjectId);

            ProjectMember member = m_mapper.Map <ProjectMember>(dto);

            project.Team.Add(member);
            await m_projectRepository.Update(project);
        }
Esempio n. 18
0
        public bool Set(MassVoucher massVoucher)
        {
            bool   isValid = true;
            double ignored = 0;

            if (massVoucher.Project == null)
            {
                isValid = SetErrorMessage("NoProjectSelected");
            }
            else if (massVoucher.VoucherType != "Contra" && massVoucher.Head == null)
            {
                isValid = SetErrorMessage("NoHeadSelected");
            }
            else if (massVoucher.Amount == 0)
            {
                isValid = SetErrorMessage("AmountCannotBeZero");
            }
            else if (massVoucher.VoucherType == "Contra" && string.IsNullOrWhiteSpace(massVoucher.ContraType))
            {
                isValid = SetErrorMessage("ContraTypeIsNotSelected");
            }
            else if (massVoucher.VoucherType == "JV" && string.IsNullOrWhiteSpace(massVoucher.JVDebitOrCredit))
            {
                isValid = SetErrorMessage("JVDebitOrCreditNotSelected");
            }
            else if (massVoucher.IsFixedAsset && string.IsNullOrWhiteSpace(massVoucher.FixedAssetName))
            {
                isValid = SetWarningMessage("NoFixedAssetParticularNameFound");
            }
            else if (massVoucher.IsCheque &&
                     (string.IsNullOrWhiteSpace(massVoucher.ChequeNo) || string.IsNullOrWhiteSpace(massVoucher.BankName)))
            {
                isValid = SetInformationMessage("NoChequeOrBankInfo");
            }
            else if (massVoucher.IsFixedAsset && massVoucher.FixedAssetDepreciationRate == 0)
            {
                isValid = SetInformationMessage("ZeroDepreciationProvidedForFixedAsset");
            }
            else if (_voucherManager.GetVouchers(massVoucher.VoucherType + "-" + massVoucher.VoucherSerialNo.ToString(), ref ignored).Count() != 0)
            {
                isValid = SetWarningMessage("VoucherAlreadyExists");
            }

            if (isValid)
            {
                _massVoucher = massVoucher;

                if (!massVoucher.VoucherType.Equals("Contra", StringComparison.OrdinalIgnoreCase))
                {
                    _projectHead = _projectHeadRepository.GetSingle(
                        ph => ph.Project.ID == massVoucher.Project.ID && ph.Head.ID == massVoucher.Head.ID);
                }
                isValid = SetEntryableRecords();
            }

            return(isValid);
        }
Esempio n. 19
0
        /// <summary>
        /// Public method to authenticate user by user name and password.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public int Authenticate(string userName, string password)
        {
            var user = _userRepo.GetSingle(u => u.UserName == userName && u.Password == password);

            if (user != null && user.Id > 0)
            {
                return(user.Id);
            }
            return(0);
        }
Esempio n. 20
0
        public ActionResult Details(int cardId = 0)
        {
            Card card = cardRepository.GetSingle(cardId);

            if (card == null)
            {
                return(HttpNotFound());
            }
            return(View(card));
        }
Esempio n. 21
0
        public ActionResult Details(int deckId = 0)
        {
            Deck deck = deckRepository.GetSingle(deckId);

            if (deck == null)
            {
                return(HttpNotFound());
            }
            return(View(deck));
        }
Esempio n. 22
0
        public IHttpActionResult Get(int id)
        {
            Product product = repository.GetSingle(id);

            if (product == null)
            {
                return(NotFound());
            }
            return(Ok(product));
        }
Esempio n. 23
0
        public ActionResult Create(int deckId = 0)
        {
            Deck deck = deckRepository.GetSingle(deckId);

            if (deck == null)
            {
                return(HttpNotFound());
            }
            ViewBag.deckId = deckId;
            return(View());
        }
Esempio n. 24
0
        public async Task <IActionResult> Index()
        {
            var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

            CustomerProfile loggedProfile = _profileRepo.GetSingle(cProfile => cProfile.UserId == loggedUser.Id);

            IEnumerable <Package> packList = _packRepo.GetAll();

            IEnumerable <Order> orderList     = _orderRepo.Query(o => o.UserId == loggedUser.Id);
            List <Order>        activeOrder   = new List <Order>();
            List <Order>        inactiveOrder = new List <Order>();

            foreach (var o in orderList)
            {
                if (o.DepartingDate >= DateTime.Now)
                {
                    o.IsActive = true;
                    activeOrder.Add(o);
                }
                else
                {
                    o.IsActive = false;
                    inactiveOrder.Add(o);
                }
            }


            DisplayCustomerProfileViewModel vm = new DisplayCustomerProfileViewModel
            {
                UserId         = loggedUser.Id,
                UserName       = loggedUser.UserName,
                Packages       = packList,
                ActiveOrders   = activeOrder,
                InactiveOrders = inactiveOrder
            };

            if (loggedProfile != null)
            {
                if (loggedProfile.ImgPath == null)
                {
                    vm.ImgPath = "admin\\person-solid.png";
                }
                else
                {
                    vm.ImgPath = loggedProfile.ImgPath;
                }
            }
            else
            {
                vm.ImgPath = "admin\\person-solid.png";
            }

            return(View(vm));
        }
        public bool CheckQuyDinh(int tuoi)
        {
            int tuoiToiDa    = _quyDinhRepository.GetSingle().TuoiToiDa;
            int tuoiToiThieu = _quyDinhRepository.GetSingle().TuoiToiThieu;

            if (tuoi < tuoiToiThieu || tuoi > tuoiToiDa)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 26
0
        public IActionResult Update(int id)
        {
            DeliveryAddress address = _addressRepo.GetSingle(a => a.DeliveryAddressId == id);

            UpdateDeliveryAddressViewModel vm = new UpdateDeliveryAddressViewModel()
            {
                DeliveryAddress = address
            };

            return(View(vm));
        }
Esempio n. 27
0
        public PersonalAccountingViewModel GetSingle(Guid orderId)
        {
            var source = _accountBookRepository.GetSingle(d => d.Id == orderId);

            return(new PersonalAccountingViewModel
            {
                Category = (PersonalAccountingViewModel.RecordCategory)source.Categoryyy,
                Date = source.Dateee,
                Remark = source.Remarkkk,
                Amount = source.Amounttt
            });
        }
Esempio n. 28
0
        public ActionResult Question(int deckId, int cardId, UserStatistic statistic)
        {
            var deck  = deckRepository.GetSingle(deckId);
            var model = new StudyDeckModel()
            {
                Deck      = deck,
                Card      = deck.Cards.Where(c => c.CardID == cardId).FirstOrDefault(),
                Statistic = statistic
            };

            return(View(model));
        }
Esempio n. 29
0
        public IActionResult Update(UpdateCategoryViewModel vm)
        {
            var user     = GetCurrentUserAsync().Result;
            var category = _categoryRepo.GetSingle(c => c.CategoryId == vm.SelectedCategoryId);

            category.Name   = vm.Name;
            category.UserId = user.Id;

            _categoryRepo.Update(category);

            return(RedirectToAction("Index", "Admin"));
        }
Esempio n. 30
0
        public ExpenseIncomeViewModel GetSingle(Guid accountBookId)
        {
            var source = _accountBookRepository.GetSingle(d => d.Id == accountBookId);
            var kind   = _classifyRepository.LookupAll().Where(c => c.Kind == "account_kind");

            return(new ExpenseIncomeViewModel
            {
                ExpenseIncometype = kind.Where(c => c.Value == source.Categoryyy).FirstOrDefault().Desc,
                CreateTime = source.Dateee,
                Money = source.Amounttt,
                Remark = source.Remarkkk
            });
        }
Esempio n. 31
0
 public UserDto GetUser(IRepository<User> userRepository, int userId)
 {
     var user = userRepository.GetSingle(u => u.UserId == userId);
     return user != null ? user.ToDto() : null;
 }
Esempio n. 32
0
 public IEnumerable<UserBlogDto> GetBlockedBlogs(IRepository<User> userRepository, int userId)
 {
     var user = userRepository.GetSingle(u => u.UserId == userId);
     return user.BlockedBlogs.Select(b => b.ToDto());
 }
 public PipelineViewDto GetPipeline(int? pipelineId, IRepository<PipelineView> pipelineRepository)
 {
     return pipelineRepository.GetSingle(p => p.PipelineViewId == pipelineId.Value).ToDto();
 }