Esempio n. 1
0
        public async Task <ActionResult <StoreResponse> > InsertStore([FromBody] PostStoresRequest model)
        {
            //insert new store

            Guid accountId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            var  rs        = await _storesService.PostStore(accountId, model);

            return(Ok(rs));
        }
Esempio n. 2
0
        public async Task <ActionResult <StoreResponse> > UpdateStore(int id, [FromBody] PostStoresRequest model)
        {
            Guid accountId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            var  rs        = await _storesService.PutStore(id, accountId, model);

            if (rs == null)
            {
                return(NotFound());
            }
            return(Ok(rs));
        }
Esempio n. 3
0
        public async Task <StoreResponse> PostStore(Guid accountId, PostStoresRequest model)
        {
            var myGeom = GeoJsonHelper.ParseStringToPoint(model.CoordinateString);

            Store insert = new Store
            {
                Name           = model.Name,
                TimeSlot       = model.TimeSlot,
                CreateDate     = DateTime.UtcNow.AddHours(7),
                BrandId        = model.BrandId,
                Geom           = myGeom,
                Address        = model.Address,
                Status         = (int?)Status.NeedApproval,
                AbilityToServe = model.AbilityToServe,
                ImageUrl       = model.ImageUrl
            };

            if (model.FloorAreaId > 0)
            {
                insert.FloorAreaId = model.FloorAreaId;
            }

            try
            {
                await _unitOfWork.Repository <Store>().InsertAsync(insert);

                await _unitOfWork.CommitAsync();

                List <StoreStreetSegmentResponse> storeStreetSegmentResponses = new List <StoreStreetSegmentResponse>();
                if (model.StreetSegmentIds != null)
                {
                    foreach (var item in model.StreetSegmentIds)
                    {
                        StoreStreetSegment storeStreetSegment = new StoreStreetSegment {
                            StoreId = insert.Id, StreetSegmentId = item
                        };
                        await _unitOfWork.Repository <StoreStreetSegment>().InsertAsync(storeStreetSegment);

                        await _unitOfWork.CommitAsync();

                        storeStreetSegmentResponses.Add(new StoreStreetSegmentResponse
                        {
                            StoreId         = storeStreetSegment.StoreId,
                            StreetSegmentId = storeStreetSegment.StreetSegmentId
                        });
                    }
                }
                await _unitOfWork.Repository <History>().InsertAsync(new History
                {
                    AccountId  = accountId,
                    Action     = (int)ActionEnum.ActionSurvey.InsertStore,
                    CreateDate = DateTime.UtcNow.AddHours(7),
                    StoreId    = insert.Id,
                });

                await _unitOfWork.CommitAsync();

                return(new StoreResponse
                {
                    Name = insert.Name,
                    Address = insert.Address,
                    FloorAreaName = insert.FloorArea?.Name,
                    BrandName = insert.Brand?.Name,
                    CreateDate = insert.CreateDate,
                    Geom = insert.Geom,
                    Id = insert.Id,
                    FloorAreaId = insert.FloorAreaId,
                    StoreStreetSegments = storeStreetSegmentResponses,
                    BrandId = insert.BrandId,
                    ImageUrl = insert.ImageUrl,
                    Status = insert.Status,
                    TimeSlot = insert.TimeSlot,
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Insert Store Error!!!", e.InnerException?.Message);
            }
        }