Пример #1
0
        public async Task <StoreResponse> PutStoreForBrand(int id, Guid accountId, int brandId, PutStoresForBrandRequest model)
        {
            var store = await _unitOfWork.Repository <Store>().GetById(id);

            if (store == null)
            {
                return(null);
            }

            if (store.BrandId != brandId)
            {
                throw new CrudException(HttpStatusCode.MethodNotAllowed, "Update Store Error!!!", "");
            }

            store.Name    = model.Name;
            store.Address = model.Address;
            if (!string.IsNullOrEmpty(model.ImageUrl))
            {
                store.ImageUrl = model.ImageUrl;
            }
            store.Address        = model.Address;
            store.TimeSlot       = model.TimeSlot;
            store.AbilityToServe = model.AbilityToServe;
            try
            {
                await _unitOfWork.Repository <Store>().Update(store, id);

                await _unitOfWork.Repository <History>().InsertAsync(new History
                {
                    AccountId  = accountId,
                    Action     = (int)ActionEnum.ActionSurvey.EditStore,
                    CreateDate = DateTime.UtcNow.AddHours(7),
                    StoreId    = store.Id,
                });

                await _unitOfWork.CommitAsync();

                return(new StoreResponse
                {
                    Name = store.Name,
                    Address = store.Address,
                    BrandName = store.Brand?.Name,
                    CreateDate = store.CreateDate,
                    Geom = store.Geom,
                    Id = store.Id,
                    BrandId = store.BrandId,
                    ImageUrl = store.ImageUrl,
                    Type = store.Brand?.Segment?.Name,
                    Status = store.Status,
                    AbilityToServe = store.AbilityToServe,
                    TimeSlot = store.TimeSlot
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Update Store Error!!!", e.InnerException?.Message);
            }
        }
Пример #2
0
        public async Task <ActionResult <StoreResponse> > UpdateStoreForBrand(int id, [FromBody] PutStoresForBrandRequest model)
        {
            Guid accountId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            int  brandId   = (bool)(!User.FindFirst("BrandId")?.Value.Equals("")) ? Convert.ToInt32(User.FindFirst("BrandId")?.Value) : 0;
            var  rs        = await _storesService.PutStoreForBrand(id, accountId, brandId, model);

            if (rs == null)
            {
                return(NotFound());
            }
            return(Ok(rs));
        }