Ejemplo n.º 1
0
        public override int GetHashCode()
        {
            int hashItemId          = ItemId == 0 ? 0 : ItemId.GetHashCode();
            int hashItemName        = Name == null ? 0 : Name.GetHashCode();
            int hashUnitMeasurement = UnitMeasurement == null ? 0 : UnitMeasurement.GetHashCode();
            int hashPrice           = Price == 0.0 ? 0 : Price.GetHashCode();

            return(hashItemId * hashItemName * hashUnitMeasurement + hashPrice);
        }
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, UnitMeasurement model)
        {
            if (model != null && ModelState.IsValid)
            {
                IRestResponse WSR = Task.Run(() => apiClient.postObject("UnidadMedida/Eliminar", model)).Result;
                if (WSR.StatusCode != HttpStatusCode.OK)
                {
                    ModelState.AddModelError("errorGeneral", JObject.Parse(WSR.Content).ToObject <Error>().Message.ToString());
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
        public async Task <IActionResult> Create([FromBody] UnitMeasurement unit)
        {
            if (ModelState.IsValid)
            {
                await _db.UnitMeasurements.AddAsync(unit);

                await _db.SaveChangesAsync();

                return(Accepted());
            }

            return(BadRequest(new { Error = "Data tidak valid." }));
        }
Ejemplo n.º 4
0
        // GET: UnitMeasurement/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UnitMeasurement unitMeasurement = db.UnitMeasurements.Find(id);

            if (unitMeasurement == null)
            {
                return(HttpNotFound());
            }
            return(View(unitMeasurement));
        }
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, UnitMeasurement model)
        {
            if (model != null && ModelState.IsValid)
            {
                model.RegisterUser = ((Commons.User)Session["USERINFO"]).UserName;
                IRestResponse WSR = Task.Run(() => apiClient.postObject("UnidadMedida/Modificar", model)).Result;
                if (WSR.StatusCode != HttpStatusCode.OK)
                {
                    ModelState.AddModelError("errorGeneral", JObject.Parse(WSR.Content).ToObject <Error>().Message.ToString());
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(string id)
        {
            try
            {
                UnitMeasurement unitMeasurement = db.UnitMeasurements.Find(id);
                db.UnitMeasurements.Remove(unitMeasurement);
                db.SaveChanges();
            }
            catch
            {
                return(RedirectToAction("Delete", new { id = id, saveChangesError = true }));
            }

            return(RedirectToAction("Index"));
        }
        public UnitMeasurement SaveUnitMeasurement(string key_unit, string description_unit, int calc_type_id)
        {
            try {
                UnitMeasurement _entity = new UnitMeasurement()
                {
                    KeyUnit         = key_unit,
                    DescriptionUnit = description_unit,
                    CalcTypeId      = calc_type_id
                };

                return(_unitMeasurementImpl.Save(_entity));
            }
            catch (Exception ex)
            {
                LoogerApplication.LoogerError(this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex);
                throw ex;
            }
        }
Ejemplo n.º 8
0
        public ActionResult Edit([Bind(Include = "UnitMeasurementId,Code,Description")] UnitMeasurement unitMeasurement)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(unitMeasurement).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again,and if the problem persists see your system administrator.");
            }

            return(View(unitMeasurement));
        }
Ejemplo n.º 9
0
        // GET: UnitMeasurement/Delete/5
        public ActionResult Delete(string id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator.";
            }
            UnitMeasurement unitMeasurement = db.UnitMeasurements.Find(id);

            if (unitMeasurement == null)
            {
                return(HttpNotFound());
            }
            return(View(unitMeasurement));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Code,Description")] UnitMeasurement unitMeasurement)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    unitMeasurement.UnitMeasurementId = Guid.NewGuid().ToString();
                    db.UnitMeasurements.Add(unitMeasurement);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again,and if the problem persists see your system administrator.");
            }

            return(View(unitMeasurement));
        }
        public async Task <IActionResult> Update(int id, [FromBody] UnitMeasurement unit)
        {
            var measurement = await _db.UnitMeasurements.FindAsync(id);

            if (measurement == null)
            {
                return(BadRequest(new { Error = "Data tidak ditemukan" }));
            }

            unit.ID = id;
            if (ModelState.IsValid)
            {
                _db.UnitMeasurements.Update(unit);
                await _db.SaveChangesAsync();

                return(Ok(unit));
            }
            return(Ok(id));
        }