/// <summary> /// Gets the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<TranscationRecord>.</returns> public async Task<TranscationRecord> Get(int id) { using (ChePingContext db = new ChePingContext()) { return await db.TranscationRecords.FirstOrDefaultAsync(u => u.Id == id); } }
/// <summary> /// Gets the cities. /// </summary> /// <returns>Task<List<System.String>>.</returns> public async Task<List<string>> GetCities() { using (ChePingContext db = new ChePingContext()) { return await db.Cities.Select(c => c.CityName).Distinct().ToListAsync(); } }
/// <summary> /// Gets the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<City>.</returns> public async Task<City> Get(int id) { using (ChePingContext db = new ChePingContext()) { return await db.Cities.FirstOrDefaultAsync(c => c.Id == id); } }
/// <summary> /// Exists the specified city. /// </summary> /// <param name="city">The city.</param> /// <returns>Task<System.Boolean>.</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); } }
/// <summary> /// Gets the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<Photo>.</returns> public async Task<Photo> Get(int id) { using (ChePingContext db = new ChePingContext()) { return await db.Photos.FirstOrDefaultAsync(p => p.Id == id); } }
/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="outlet">The outlet.</param> /// <returns>Task<Outlet>.</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; }
/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="user">The user.</param> /// <returns>Task<User>.</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; }
/// <summary> /// Creates the specified photo. /// </summary> /// <param name="photo">The photo.</param> /// <returns>Task<Photo>.</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<PaginatedList<TranscationRecord>>.</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); } }
/// <summary> /// Creates the specified user. /// </summary> /// <param name="user">The user.</param> /// <returns>Task<User>.</returns> public async Task<User> Create(User user) { user.Available = true; using (ChePingContext db = new ChePingContext()) { await db.SaveAsync(user); } return user; }
/// <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); } } }
/// <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<PaginatedList<TranscationRecord>>.</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); } }
/// <summary> /// Disables the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<Outlet>.</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; } }
/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="model">The model.</param> /// <returns>Task<Model>.</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; }
/// <summary> /// Disables the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<Model>.</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; } }
/// <summary> /// Creates the specified city. /// </summary> /// <param name="city">The city.</param> /// <returns>Task<City>.</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; }
/// <summary> /// Disables the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task<User>.</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; } }
/// <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<CaseDto>.</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); }
/// <summary> /// Creates the specified outlet. /// </summary> /// <param name="outlet">The outlet.</param> /// <returns>Task<Outlet>.</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; }
/// <summary> /// Creates the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns>Task<Model>.</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; }
/// <summary> /// accept price as an asynchronous operation. /// </summary> /// <param name="caseId">The case identifier.</param> /// <returns>Task<Case>.</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; } }
/// <summary> /// Indexes this instance. /// </summary> /// <param name="includeUnavailable">if set to <c>true</c> [include unavailable].</param> /// <returns>Task<List<User>>.</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(); } }
/// <summary> /// Logins the specified login name. /// </summary> /// <param name="loginName">Name of the login.</param> /// <param name="password">The password.</param> /// <returns>Task<User>.</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); } }
/// <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<List<User>>.</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(); } }
/// <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<PaginatedList<User>>.</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); } }
/// <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<User>.</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); } }
/// <summary> /// Rejects the specified case identifier. /// </summary> /// <param name="caseId">The case identifier.</param> /// <param name="message">The message.</param> /// <returns>Task<Case>.</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; } }
/// <summary> /// Indexes this instance. /// </summary> /// <returns>Task<List<Case>>.</returns> public async Task<List<Case>> IndexAsync() { using (ChePingContext db = new ChePingContext()) { return await db.Cases.ToListAsync(); } }
/// <summary> /// get warning as an asynchronous operation. /// </summary> /// <param name="user">The user.</param> /// <returns>Task<List<Case>>.</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>(); } } }
/// <summary> /// Gets the vehicle inspection. /// </summary> /// <param name="caseId">The case identifier.</param> /// <returns>Task<VehicleInspection>.</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); } }