// PUT api/ProductType/5
        public HttpResponseMessage Putproducttype(short id, producttype producttype)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != producttype.producttypeid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(producttype).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ProductTypeModel model = new ProductTypeModel();
        producttype      p     = createProductType();

        lblResult.Text = model.insertProductType(p);
    }
        public int?ConfigureProductTypeName(string productTypeName, string productGroup)
        {
            // check if the product type name exist in Amazon sub-category
            var subCategory = _context.amazonsubcategories.FirstOrDefault(x => x.Name.Equals(productTypeName, StringComparison.InvariantCultureIgnoreCase));

            if (subCategory == null)
            {
                _logger.LogWarning(LogEntryType.ProductTypeService, string.Format("ProductType: {0} - ProductGroup: {1} not found in Amazon Sub-Category", productTypeName, productGroup));
                return(null); // should null for the unknown product type for now
            }

            // get the product type if it has and return its ID
            var productType = _context.producttypes
                              .FirstOrDefault(x => x.AmazonMainCategoryCode == subCategory.ParentCode && x.AmazonSubCategoryCode == subCategory.Code);

            if (productType != null)
            {
                return(productType.Id);
            }

            // otherwise, let's create new product type
            var newProductType = new producttype
            {
                TypeName = string.Format("{0} - {1}", subCategory.amazoncategory.Name, subCategory.Name),
                AmazonMainCategoryCode = subCategory.ParentCode,
                AmazonSubCategoryCode  = subCategory.Code,
            };

            // add save it to database
            _context.producttypes.Add(newProductType);
            _context.SaveChanges();

            return(newProductType.Id);
        }
Beispiel #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            producttype producttype = db.producttypes.Find(id);

            db.producttypes.Remove(producttype);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
    private producttype createProductType()
    {
        producttype p = new producttype();

        p.name = txtName.Text;

        return(p);
    }
        public async Task <DTOproducttype> Postproducttype(DTOproducttype newDTO)
        {
            producttype newProd = EntityMapper.updateEntity(null, newDTO);

            db.producttypes.Add(newProd);
            await db.SaveChangesAsync();

            return(newDTO);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public JsonResult EditJson(producttype parm)
        {
            parm.CreateDate = DateTime.Now;
            parm.StaffID    = UserInfo.Id;
            parm.StaffName  = UserInfo.UserName;
            var json = _typeBll.Edit(parm);

            return(Json(json));
        }
        public async Task <IHttpActionResult> Putproducttype(int ID, DTOproducttype editedDTO)
        {
            producttype toUpdate = db.producttypes.Find(ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "producttypeId,code,name,description")] producttype producttype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(producttype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(producttype));
 }
Beispiel #10
0
        public ActionResult Create([Bind(Include = "producttypeId,code,name,description")] producttype producttype)
        {
            if (ModelState.IsValid)
            {
                db.producttypes.Add(producttype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(producttype));
        }
        // GET api/ProductType/5
        public producttype Getproducttype(short id)
        {
            producttype producttype = db.producttypes.Find(id);

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

            return(producttype);
        }
Beispiel #12
0
        public static producttype updateEntity(producttype entityObjct, DTOproducttype dto)
        {
            if (entityObjct == null)
            {
                entityObjct = new producttype();
            }

            entityObjct.ProductType_ID  = dto.ProductType_ID;
            entityObjct.ProductTypeName = dto.ProductTypeName;

            return(entityObjct);
        }
Beispiel #13
0
 public ApiMessage <string> Edit(producttype t)
 {
     if (string.IsNullOrEmpty(t.ID))
     {
         t.ID = Guid.NewGuid().ToString();
         t.Insert();
     }
     else
     {
         t.Update();
     }
     return(new ApiMessage <string>());
 }
Beispiel #14
0
        // GET: /CRM/producttypes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            producttype producttype = db.producttypes.Find(id);

            if (producttype == null)
            {
                return(HttpNotFound());
            }
            return(View(producttype));
        }
    public string insertProductType(producttype productType)
    {
        try
        {
            autopartsEntities db = new autopartsEntities();
            db.producttypes.Add(productType);
            db.SaveChanges();

            return(productType.name + " was successfully inserted");
        }
        catch (Exception e)
        {
            return("Error :" + e);
        }
    }
        // POST api/ProductType
        public HttpResponseMessage Postproducttype(producttype producttype)
        {
            if (ModelState.IsValid)
            {
                db.producttypes.Add(producttype);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, producttype);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = producttype.producttypeid }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
    public string deleteProductType(int id)
    {
        try
        {
            autopartsEntities db = new autopartsEntities();
            producttype       p  = db.producttypes.Find(id);

            db.producttypes.Attach(p);
            db.producttypes.Remove(p);
            db.SaveChanges();
            return(p.name + " was successfully deleted");
        }
        catch (Exception e)
        {
            return("Error :" + e);
        }
    }
    public string updateProductType(int id, producttype productType)
    {
        try
        {
            autopartsEntities db = new autopartsEntities();
            //Fetch
            producttype p = db.producttypes.Find(id);
            p.name = productType.name;


            db.SaveChanges();

            return(productType.name + " was successfully updated");
        }
        catch (Exception e)
        {
            return("Error :" + e);
        }
    }
        // DELETE api/ProductType/5
        public HttpResponseMessage Deleteproducttype(short id)
        {
            producttype producttype = db.producttypes.Find(id);

            if (producttype == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.producttypes.Remove(producttype);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, producttype));
        }
Beispiel #20
0
 public ApiMessage <string> Edit(producttype parm)
 {
     return(_dal.Edit(parm));
 }
Beispiel #21
0
 public ProductType(producttype p)
 {
     this.Id          = p.idProductType;
     this.TypeName    = p.TypeName;
     this.Description = p.Description;
 }