Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public async Task<IHttpActionResult> Create(OutletDto dto)
        {
            Outlet outlet = new Outlet
            {
                Available = true,
                Address = dto.Address,
                Cellphone = dto.Cellphone,
                CityId = dto.CityId,
                Contact = dto.Contact,
                OutletName = dto.OutletName
            };

            if (await this.outletService.Exist(outlet))
            {
                return this.BadRequest("网点信息已经存在");
            }

            //if not exist, retrieve the city data by cityId and add it to outlet entity.
            City city = await this.cityService.Get(outlet.CityId);
            outlet.CityName = city.CityName;
            outlet.ProvinceName = city.ProvinceName;

            return this.Ok((await this.outletService.Create(outlet)).ToDto());
        }
Exemplo n.º 4
0
        public async Task<IHttpActionResult> Exist(OutletDto dto)
        {
            Outlet outlet = new Outlet
            {
                CityId = dto.CityId,
                OutletName = dto.OutletName
            };

            return this.Ok(new BoolResponse { Result = await this.outletService.Exist(outlet) });
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Exists the specified outlet.
 /// </summary>
 /// <param name="outlet">The outlet.</param>
 /// <returns>Task&lt;System.Boolean&gt;.</returns>
 public async Task<bool> Exist(Outlet outlet)
 {
     using (ChePingContext db = new ChePingContext())
     {
         //use cityId and outletName to match
         return await db.Outlets.AnyAsync(o => o.CityId == outlet.CityId && o.OutletName == outlet.OutletName);
     }
 }