Ejemplo n.º 1
0
        /// <summary>
        ///     Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="user">The user.</param>
        /// <returns>Task&lt;User&gt;.</returns>
        public async Task<User> Edit(int id, User user)
        {
            using (ChePingContext db = new ChePingContext())
            {
                await db.SaveOrUpdateAsync(user, t => t.Id == id);
            }

            return user;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>Task&lt;User&gt;.</returns>
        public async Task<User> Create(User user)
        {
            user.Available = true;

            using (ChePingContext db = new ChePingContext())
            {
                await db.SaveAsync(user);
            }

            return user;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     get todos as an asynchronous operation.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>Task&lt;List&lt;Case&gt;&gt;.</returns>
        public async Task<List<Case>> GetTodosAsync(User user)
        {
            using (ChePingContext db = new ChePingContext())
            {
                switch (user.JobTitle)
                {
                    case JobTitle.Purchaser:
                        return await db.Cases.Where(c => PurchaserTodoStates.Contains(c.State) && c.PurchaserId == user.Id).ToListAsync();

                    case JobTitle.Valuer:
                        return await db.Cases.Where(c => ValuerTodoStates.Contains(c.State) && c.ValuerId == user.Id).ToListAsync();

                    case JobTitle.Querying:
                        return await db.Cases.Where(c => QueryingTodoStates.Contains(c.State) && c.QueryingId == user.Id).ToListAsync();

                    case JobTitle.Director:
                        return await db.Cases.Where(c => DirectorTodoStates.Contains(c.State) && c.DirectorId == user.Id).ToListAsync();

                    case JobTitle.Manager:
                        return await db.Cases.Where(c => ManagerTodoStates.Contains(c.State) && c.ManagerId == user.Id).ToListAsync();

                    default:
                        return new List<Case>();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     get warning as an asynchronous operation.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>Task&lt;List&lt;Case&gt;&gt;.</returns>
        public async Task<List<Case>> GetWarningAsync(User user)
        {
            using (ChePingContext db = new ChePingContext())
            {
                switch (user.JobTitle)
                {
                    case JobTitle.Purchaser:
                        return await db.Cases.Where(c => PurchaserWarningStates.Contains(c.State) && c.Abandon == false && c.PurchaserId == user.Id).ToListAsync();

                    case JobTitle.Director:
                        return await db.Cases.Where(c => DirectorWarningStates.Contains(c.State) && c.Abandon == false && c.DirectorId == user.Id).ToListAsync();

                    case JobTitle.Manager:
                        return await db.Cases.Where(c => ManagerWarningStates.Contains(c.State) && c.Abandon == false && c.ManagerId == user.Id).ToListAsync();

                    default:
                        return new List<Case>();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     get cases as an asynchronous operation.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="carType">Type of the car.</param>
        /// <returns>Task&lt;PaginatedList&lt;Case&gt;&gt;.</returns>
        public async Task<PaginatedList<Case>> GetCasesAsync(User user, int pageIndex, int pageSize, CarType carType)
        {
            using (ChePingContext db = new ChePingContext())
            {
                int totalCount = 0;
                List<Case> cases = new List<Case>();
                switch (user.JobTitle)
                {
                    case JobTitle.Purchaser:
                        totalCount = await db.Cases.Where(c => c.PurchaserId == user.Id && c.CaseType == carType).CountAsync();
                        cases = await db.Cases.Where(c => c.PurchaserId == user.Id && c.CaseType == carType).OrderByDescending(c => c.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                        break;

                    case JobTitle.Valuer:
                        totalCount = await db.Cases.Where(c => c.ValuerId == user.Id && c.CaseType == carType).CountAsync();
                        cases = await db.Cases.Where(c => c.ValuerId == user.Id && c.CaseType == carType).OrderByDescending(c => c.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                        break;

                    case JobTitle.Querying:
                        totalCount = await db.Cases.Where(c => c.QueryingId == user.Id && c.CaseType == carType).CountAsync();
                        cases = await db.Cases.Where(c => c.QueryingId == user.Id && c.CaseType == carType).OrderByDescending(c => c.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                        break;

                    case JobTitle.Director:
                        totalCount = await db.Cases.Where(c => c.DirectorId == user.Id && c.CaseType == carType).CountAsync();
                        cases = await db.Cases.Where(c => c.DirectorId == user.Id && c.CaseType == carType).OrderByDescending(c => c.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                        break;

                    case JobTitle.Manager:
                        totalCount = await db.Cases.Where(c => c.ManagerId == user.Id).CountAsync();
                        cases = await db.Cases.Where(c => c.ManagerId == user.Id).OrderByDescending(c => c.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                        break;
                }

                return new PaginatedList<Case>(pageIndex, pageSize, totalCount, cases);
            }
        }