/// <summary>
 /// Gets the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>Task&lt;TranscationRecord&gt;.</returns>
 public async Task<TranscationRecord> Get(int id)
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.TranscationRecords.FirstOrDefaultAsync(u => u.Id == id);
     }
 }
예제 #2
0
 /// <summary>
 ///     Gets the cities.
 /// </summary>
 /// <returns>Task&lt;List&lt;System.String&gt;&gt;.</returns>
 public async Task<List<string>> GetCities()
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Cities.Select(c => c.CityName).Distinct().ToListAsync();
     }
 }
예제 #3
0
 /// <summary>
 ///     Gets the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>Task&lt;City&gt;.</returns>
 public async Task<City> Get(int id)
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Cities.FirstOrDefaultAsync(c => c.Id == id);
     }
 }
예제 #4
0
 /// <summary>
 ///     Exists the specified city.
 /// </summary>
 /// <param name="city">The city.</param>
 /// <returns>Task&lt;System.Boolean&gt;.</returns>
 public async Task<bool> Exist(City city)
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Cities.AnyAsync(c => c.ProvinceName == city.ProvinceName && c.CityName == city.CityName);
     }
 }
예제 #5
0
 /// <summary>
 ///     Gets the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>Task&lt;Photo&gt;.</returns>
 public async Task<Photo> Get(int id)
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Photos.FirstOrDefaultAsync(p => p.Id == id);
     }
 }
예제 #6
0
        /// <summary>
        ///     Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="outlet">The outlet.</param>
        /// <returns>Task&lt;Outlet&gt;.</returns>
        public async Task<Outlet> Edit(int id, Outlet outlet)
        {
            using (ChePingContext db = new ChePingContext())
            {
                await db.SaveOrUpdateAsync(outlet, o => o.Id == id);
            }

            return outlet;
        }
예제 #7
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;
        }
예제 #8
0
 /// <summary>
 ///     Creates the specified photo.
 /// </summary>
 /// <param name="photo">The photo.</param>
 /// <returns>Task&lt;Photo&gt;.</returns>
 public async Task<int> Create(Photo photo)
 {
     using (ChePingContext db = new ChePingContext())
     {
         photo.UploadTime = DateTime.UtcNow.AddHours(8);
         await db.SaveAsync(photo);
     }
     return photo.Id;
 }
        /// <summary>
        /// Gets the paginated.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns>Task&lt;PaginatedList&lt;TranscationRecord&gt;&gt;.</returns>
        public async Task<PaginatedList<TranscationRecord>> GetPaginated(int pageIndex, int pageSize)
        {
            using (ChePingContext db = new ChePingContext())
            {
                int count = await db.TranscationRecords.CountAsync();
                List<TranscationRecord> transcationRecords = await db.TranscationRecords.OrderBy(u => u.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();

                return new PaginatedList<TranscationRecord>(pageIndex, pageSize, count, transcationRecords);
            }
        }
예제 #10
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;
        }
예제 #11
0
 /// <summary>
 ///     Sends the notice message.
 /// </summary>
 /// <param name="userId">The user identifier.</param>
 /// <returns>Task.</returns>
 public async Task SendNoticeMessage(int userId)
 {
     using (ChePingContext db = new ChePingContext())
     {
         User user = await db.Users.FirstOrDefaultAsync(u => u.Id == userId);
         if (user != null)
         {
             await this.SendNoticeMessage(user.Cellphone);
         }
     }
 }
예제 #12
0
        /// <summary>
        /// Gets the paginated.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="modelId">The model identifier.</param>
        /// <param name="minMileage">The minimum mileage.</param>
        /// <param name="maxMileage">The maximum mileage.</param>
        /// <param name="licenseTime">The license time.</param>
        /// <returns>Task&lt;PaginatedList&lt;TranscationRecord&gt;&gt;.</returns>
        public async Task<PaginatedList<TranscationRecord>> GetPaginated(int pageIndex, int pageSize, int modelId, int minMileage, int maxMileage, DateTime licenseTime)
        {
            using (ChePingContext db = new ChePingContext())
            {
                DateTime start = new DateTime(licenseTime.Year, 1, 1);
                DateTime end = start.AddYears(1).AddMilliseconds(-1);

                int count = await db.TranscationRecords.CountAsync();
                List<TranscationRecord> transcationRecords = await db.TranscationRecords.Where(t => t.ModelId == modelId && t.Mileage >= minMileage && t.Mileage <= maxMileage && t.LicenseTime >= start &&
                                t.LicenseTime <= end).OrderBy(u => u.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();

                return new PaginatedList<TranscationRecord>(pageIndex, pageSize, count, transcationRecords);
            }
        }
예제 #13
0
        /// <summary>
        ///     Disables the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>Task&lt;Outlet&gt;.</returns>
        public async Task<Outlet> Disable(int id)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Outlet outlet = await db.Outlets.FirstOrDefaultAsync(o => o.Id == id);
                if (outlet != null && outlet.Available)
                {
                    outlet.Available = false;
                    await db.ExecuteSaveChangesAsync();
                }

                return outlet;
            }
        }
예제 #14
0
        /// <summary>
        ///     Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="model">The model.</param>
        /// <returns>Task&lt;Model&gt;.</returns>
        /// <exception cref="System.ApplicationException">车型信息已经存在</exception>
        public async Task<Model> Edit(int id, Model model)
        {
            if (await this.Exist(model))
            {
                throw new ApplicationException("车型信息已经存在");
            }

            using (ChePingContext db = new ChePingContext())
            {
                await db.SaveOrUpdateAsync(model, t => t.Id == id);
            }

            return model;
        }
예제 #15
0
        /// <summary>
        ///     Disables the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>Task&lt;Model&gt;.</returns>
        public async Task<Model> Disable(int id)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Model model = await db.Models.FirstOrDefaultAsync(m => m.Id == id);
                if (model != null && model.Available)
                {
                    model.Available = false;
                    await db.ExecuteSaveChangesAsync();
                }

                return model;
            }
        }
예제 #16
0
        /// <summary>
        ///     Creates the specified city.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <returns>Task&lt;City&gt;.</returns>
        /// <exception cref="ApplicationException">城市信息已经存在</exception>
        public async Task<City> Create(City city)
        {
            if (await this.Exist(city))
            {
                throw new ApplicationException("城市信息已经存在");
            }

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

            return city;
        }
예제 #17
0
        /// <summary>
        ///     Disables the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>Task&lt;User&gt;.</returns>
        public async Task<User> Disable(int id)
        {
            using (ChePingContext db = new ChePingContext())
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Id == id);
                if (user != null && user.Available)
                {
                    user.Available = false;
                    await db.ExecuteSaveChangesAsync();
                }

                return user;
            }
        }
예제 #18
0
        /// <summary>
        ///     add case as an asynchronous operation.
        /// </summary>
        /// <param name="case">The case.</param>
        /// <param name="info">The information.</param>
        /// <param name="photos">The photos.</param>
        /// <returns>Task&lt;CaseDto&gt;.</returns>
        public async Task<Case> AddCaseAsync(Case @case, VehicleInfo info, IEnumerable<int> photos)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Model model = await db.Models.FirstOrDefaultAsync(m => m.Brand == info.BrandName &&
                                                                       m.Series == info.SeriesName && m.Modeling == info.ModelName);

                Color outerColor = await db.Colors.FirstOrDefaultAsync(c => c.ColorName == info.OuterColorName);

                if (outerColor == null)
                {
                    info.OuterColor = -1;
                }
                else
                {
                    info.OuterColor = outerColor.Id;
                }

                Color innerColor = await db.Colors.FirstOrDefaultAsync(c => c.ColorName == info.InnerColorName);

                if (innerColor == null)
                {
                    info.InnerColor = -1;
                }
                else
                {
                    info.InnerColor = innerColor.Id;
                }

                if (model == null)
                {
                    info.ModelId = -1;
                }
                else
                {
                    info.ModelId = model.Id;
                    info.BrandName = model.Brand;
                    info.SeriesName = model.Series;
                    info.ModelName = model.Modeling;
                }
            }

            if (info.ModelId == -1)
            {
                return await this.AddSpecialCaseAsync(@case, info, photos);
            }

            return await this.AddGeneralCaseAsync(@case, info, photos);
        }
예제 #19
0
        /// <summary>
        ///     Creates the specified outlet.
        /// </summary>
        /// <param name="outlet">The outlet.</param>
        /// <returns>Task&lt;Outlet&gt;.</returns>
        /// <exception cref="System.ApplicationException">网点信息已经存在</exception>
        /// <exception cref="ApplicationException">网点信息已经存在</exception>
        public async Task<Outlet> Create(Outlet outlet)
        {
            if (await this.Exist(outlet))
            {
                throw new ApplicationException("网点信息已经存在");
            }
            outlet.Available = true;

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

            return outlet;
        }
예제 #20
0
        /// <summary>
        ///     Creates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>Task&lt;Model&gt;.</returns>
        /// <exception cref="System.ApplicationException">车型信息已经存在</exception>
        public async Task<Model> Create(Model model)
        {
            if (await this.Exist(model))
            {
                throw new ApplicationException("车型信息已经存在");
            }

            model.Available = true;

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

            return model;
        }
예제 #21
0
        /// <summary>
        ///     accept price as an asynchronous operation.
        /// </summary>
        /// <param name="caseId">The case identifier.</param>
        /// <returns>Task&lt;Case&gt;.</returns>
        /// <exception cref="System.ApplicationException">未能加载事项信息</exception>
        public async Task<Case> AcceptPriceAsync(int caseId)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId);
                if (@case == null)
                {
                    throw new ApplicationException("未能加载事项信息");
                }

                if (@case.State == State.Qiatan)
                {
                    @case.State = State.ShenqingDakuan;
                    this.RecordTime(@case, State.Qiatan);

                    await db.ExecuteSaveChangesAsync();
                }

                return @case;
            }
        }
예제 #22
0
 /// <summary>
 ///     Indexes this instance.
 /// </summary>
 /// <param name="includeUnavailable">if set to <c>true</c> [include unavailable].</param>
 /// <returns>Task&lt;List&lt;User&gt;&gt;.</returns>
 public async Task<List<User>> Index(bool includeUnavailable = false)
 {
     using (ChePingContext db = new ChePingContext())
     {
         if (includeUnavailable)
         {
             return await db.Users.ToListAsync();
         }
         return await db.Users.Where(u => u.Available).ToListAsync();
     }
 }
예제 #23
0
 /// <summary>
 ///     Logins the specified login name.
 /// </summary>
 /// <param name="loginName">Name of the login.</param>
 /// <param name="password">The password.</param>
 /// <returns>Task&lt;User&gt;.</returns>
 public async Task<User> Login(string loginName, string password)
 {
     password = MD5Hash.ComputeMD5Hash(password);
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Users.FirstOrDefaultAsync(u => u.Cellphone == loginName && u.Password == password);
     }
 }
예제 #24
0
 /// <summary>
 ///     Gets the by cellphone.
 /// </summary>
 /// <param name="cellphone">The cellphone.</param>
 /// <param name="includeUnavailable">if set to <c>true</c> [include unavailable].</param>
 /// <returns>Task&lt;List&lt;User&gt;&gt;.</returns>
 public async Task<List<User>> GetByCellphone(string cellphone, bool includeUnavailable = false)
 {
     using (ChePingContext db = new ChePingContext())
     {
         if (includeUnavailable)
         {
             return await db.Users.Where(u => u.Cellphone == cellphone).ToListAsync();
         }
         return await db.Users.Where(u => u.Cellphone == cellphone && u.Available).ToListAsync();
     }
 }
예제 #25
0
        /// <summary>
        ///     Gets the paginated.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="includeUnavailable">if set to <c>true</c> [include unavailable].</param>
        /// <returns>Task&lt;PaginatedList&lt;User&gt;&gt;.</returns>
        public async Task<PaginatedList<User>> GetPaginated(int pageIndex, int pageSize, bool includeUnavailable = false)
        {
            using (ChePingContext db = new ChePingContext())
            {
                int count;
                List<User> users;
                if (includeUnavailable)
                {
                    count = await db.Users.CountAsync();
                    users = await db.Users.OrderBy(u => u.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                }
                else
                {
                    count = await db.Users.CountAsync(u => u.Available);
                    users = await db.Users.Where(u => u.Available).OrderBy(u => u.Id).Skip(pageSize * pageIndex).Take(pageSize).ToListAsync();
                }

                return new PaginatedList<User>(pageIndex, pageSize, count, users);
            }
        }
예제 #26
0
 /// <summary>
 ///     Gets the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="includeUnavailable">if set to <c>true</c> [include unavailable].</param>
 /// <returns>Task&lt;User&gt;.</returns>
 public async Task<User> Get(int id, bool includeUnavailable = false)
 {
     using (ChePingContext db = new ChePingContext())
     {
         if (includeUnavailable)
         {
             return await db.Users.FirstOrDefaultAsync(u => u.Id == id);
         }
         return await db.Users.FirstOrDefaultAsync(u => u.Id == id && u.Available);
     }
 }
예제 #27
0
        /// <summary>
        ///     Rejects the specified case identifier.
        /// </summary>
        /// <param name="caseId">The case identifier.</param>
        /// <param name="message">The message.</param>
        /// <returns>Task&lt;Case&gt;.</returns>
        /// <exception cref="System.ApplicationException">未能加载事项信息</exception>
        public async Task<Case> RejectAsync(int caseId, string message)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId);
                if (@case == null)
                {
                    throw new ApplicationException("未能加载事项信息");
                }

                this.RecordTime(@case, @case.State);

                switch (@case.State)
                {
                    case State.Shenhe:
                        @case.State = State.ShenheShibai;
                        break;

                    case State.Yanche:
                        @case.State = State.YancheShibai;
                        break;

                    case State.Baojia:
                        @case.State = State.FangqiBaojia;
                        break;

                    case State.Qiatan:
                        @case.State = State.QiatanShibai;
                        break;

                    case State.ShenqingDakuan:
                        @case.State = State.FangqiShenqingDakuan;
                        break;

                    case State.DakuanShenhe:
                        @case.State = State.DakuanShenheShibai;
                        break;

                    case State.Caigou:
                        @case.State = State.CaigouShibai;
                        break;
                }

                @case.AbandonReason = message;
                @case.Abandon = false;
                await db.ExecuteSaveChangesAsync();

                return @case;
            }
        }
예제 #28
0
 /// <summary>
 ///     Indexes this instance.
 /// </summary>
 /// <returns>Task&lt;List&lt;Case&gt;&gt;.</returns>
 public async Task<List<Case>> IndexAsync()
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Cases.ToListAsync();
     }
 }
예제 #29
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>();
                }
            }
        }
예제 #30
0
        /// <summary>
        ///     Gets the vehicle inspection.
        /// </summary>
        /// <param name="caseId">The case identifier.</param>
        /// <returns>Task&lt;VehicleInspection&gt;.</returns>
        /// <exception cref="System.ApplicationException">未能加载事项信息</exception>
        public async Task<VehicleInspection> GetVehicleInspectionAsync(int caseId)
        {
            using (ChePingContext db = new ChePingContext())
            {
                Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId);
                if (@case == null)
                {
                    throw new ApplicationException("未能加载事项信息");
                }

                return await db.VehicleInspections.FirstOrDefaultAsync(v => v.Id == @case.VehicleInspecId);
            }
        }