Exemplo n.º 1
0
        public ActionResult InternalLocationEdit(InternalLocationDTO internalLocationDTO)
        {
            if (ModelState.IsValid)
            {
                //Replace with updated location
                using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
                {
                    var responseMessage = httpClient.PutAsJsonAsync("api/BusinessAPI/BusinessLocation/" + internalLocationDTO.BusinessLocationId.ToString() + "/InternalLocation/" + internalLocationDTO.Id.ToString(), internalLocationDTO).Result;
                    responseMessage.EnsureSuccessStatusCode();

                    CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS_LOCATION + internalLocationDTO.BusinessLocationId.ToString()); //Remove the stale business item from the cache
                    CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + internalLocationDTO.BusinessId.ToString());                  //Remove the stale business item from the cache

                    return(RedirectToAction("InternalLocationIndex", new { businesslocationid = internalLocationDTO.BusinessLocationId }));
                }
            }
            else
            {
                return(PartialView(internalLocationDTO));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage PutinternalLocation(Guid businessLocationId, Guid internalLocationId, InternalLocationDTO internalLocationDTO)
        {
            if (ClaimsAuthorization.CheckAccess("Put", "BusinessLocationId", businessLocationId.ToString()))
            {
                if (ModelState.IsValid)
                {
                    var internalLocation = MapperFacade.MapperConfiguration.Map <InternalLocationDTO, InternalLocation>(internalLocationDTO, db.InternalLocations.Single(l => l.Id == internalLocationId));

                    db.Entry(internalLocation).State = EntityState.Modified;
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage PostinternalLocation(Guid businesslocationId, Guid internalLocationId, InternalLocationDTO internalLocationDTO)
        {
            BusinessLocation businessLocation = db.BusinessLocations.Find(businesslocationId);

            if (businessLocation == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (ClaimsAuthorization.CheckAccess("Put", "BusinessLocationId", businessLocation.Id.ToString()))
            {
                if (ModelState.IsValid)
                {
                    var location = MapperFacade.MapperConfiguration.Map <InternalLocationDTO, InternalLocation>(internalLocationDTO);
                    location.Id      = Guid.NewGuid(); //Assign new ID on save.
                    location.Enabled = true;

                    //Lookup Business and attach, so that no updates or inserts are performed on BusinessType lookup table
                    location.BusinessLocation = db.BusinessLocations.SingleOrDefault(b => b.Id == businesslocationId);

                    db.InternalLocations.Add(location);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.Created));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }