Example #1
0
        // POST: api/Regencys
        public HttpResponseMessage InsertRegency(RegencyVM regencyVM)
        {
            var message = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Wrong Parameter");
            var result  = _iRegencyService.Insert(regencyVM);

            if (result)
            {
                message = Request.CreateResponse(HttpStatusCode.OK, "Successfully Added");
            }
            return(message);
        }
Example #2
0
 public bool Insert(RegencyVM regencyVM)
 {
     if (string.IsNullOrWhiteSpace(regencyVM.Name))
     {
         return(status);
     }
     else
     {
         return(iRegencyRepository.Insert(regencyVM));
     }
 }
Example #3
0
 public bool Update(int id, RegencyVM regencyVM)
 {
     if (string.IsNullOrWhiteSpace(regencyVM.Name))
     {
         return(status);
     }
     else
     {
         var result = _regencyRepository.Update(id, regencyVM);
         return(result);
     }
 }
        public bool Update(int id, RegencyVM regencyVM)
        {
            var get         = Get(id);
            var getProvince = applicationContext.Provinces.SingleOrDefault(x => x.IsDelete == false && x.Id == regencyVM.ProvinceId);

            get.Province = getProvince;
            get.Update(regencyVM);
            applicationContext.Entry(get).State = EntityState.Modified;
            var result = applicationContext.SaveChanges();

            return(result > 0);
        }
        public bool Insert(RegencyVM regencyVM)
        {
            var push = new Regency(regencyVM);
            //ini nih foreign key
            var getProvince = applicationContext.Provinces.SingleOrDefault(x => x.IsDelete == false && x.Id == regencyVM.ProvinceId);

            push.Province = getProvince;
            applicationContext.Regencies.Add(push);
            var result = applicationContext.SaveChanges();

            return(result > 0);
        }
        public bool Insert(RegencyVM regencyVM)
        {
            var push         = new Regency(regencyVM);
            var getProviceId = myContext.Provinces.Find(regencyVM.Province_Id);

            push.Province = getProviceId;
            myContext.Regencys.Add(push);
            var result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            return(status);
        }
Example #7
0
        public HttpResponseMessage UpdateRegency(int id, RegencyVM regencyVM)
        {
            var message = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Bad Request");

            if (string.IsNullOrWhiteSpace(id.ToString()))
            {
                message = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Id");
            }
            else
            {
                var get = _iRegencyService.Update(id, regencyVM);
                if (get)
                {
                    message = Request.CreateResponse(HttpStatusCode.OK, get);
                    return(message);
                }
            }
            return(message);
        }
        public void InsertOrUpdate(RegencyVM regencyVM)
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:12280/api/");
            var myContent   = JsonConvert.SerializeObject(regencyVM);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            if (regencyVM.Id.Equals(0))
            {
                var result = client.PostAsync("Regencies", byteContent).Result;
            }
            else
            {
                var result = client.PutAsync("Regencies/" + regencyVM.Id, byteContent).Result;
            }
        }
        public bool Update(int id, RegencyVM regencyVM)
        {
            var put          = Get(id);
            var getProviceId = myContext.Provinces.Find(regencyVM.Province_Id);

            put.Province = getProviceId;
            put.Update(regencyVM);
            myContext.Entry(put).State = EntityState.Modified;
            var result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            return(status);
        }
        public JsonResult GetById(int id)
        {
            RegencyVM regencyVM = null;
            var       client    = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:12280/api/");
            var responseTask = client.GetAsync("Districts/" + id);

            responseTask.Wait();
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var readTask = result.Content.ReadAsAsync <RegencyVM>();
                readTask.Wait();
                regencyVM = readTask.Result;
            }
            else
            {
                // try to find something
            }
            return(Json(regencyVM, JsonRequestBehavior.AllowGet));
        }
Example #11
0
 public void Update(RegencyVM regencyVM)
 {
     this.Name       = regencyVM.Name;
     this.UpdateDate = DateTime.Now.ToLocalTime();
 }
Example #12
0
 public Regency(RegencyVM regencyVM)
 {
     this.Name       = regencyVM.Name;
     this.CreateDate = DateTime.Now.ToLocalTime();
 }
Example #13
0
 public Regency(RegencyVM regencyVM)
 {
     this.Name       = regencyVM.Name;
     this.CreateDate = DateTimeOffset.Now.LocalDateTime;
 }
Example #14
0
 public void Update(RegencyVM regencyVM)
 {
     this.Name       = regencyVM.Name;
     this.UpdateDate = DateTimeOffset.Now.LocalDateTime;
 }
Example #15
0
 public bool Update(int id, RegencyVM regencyVM)
 {
     return(iRegencyRepository.Update(id, regencyVM));
 }