Example #1
0
        public IHttpActionResult PosttypeFactory(TypeFactoryViewModel Type_FactoryView_Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            typeFactory typeFactory_db;

            try
            {
                typeFactory_db = new typeFactory {
                    Id = Type_FactoryView_Model.Id, No = Type_FactoryView_Model.No, Name = Type_FactoryView_Model.Name
                };
                db.typeFactories.Add(typeFactory_db);
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "DbEntityValidationException:" + ex.Message));
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }


            return(CreatedAtRoute("DefaultApi", new { id = typeFactory_db.Id }, ToViewModel(typeFactory_db)));
        }
Example #2
0
        public IHttpActionResult GettypeFactory(int id)
        {
            typeFactory typeFactory = db.typeFactories.Find(id);

            if (typeFactory == null)
            {
                return(NotFound());
            }
            return(Ok(ToViewModel(typeFactory)));
        }
Example #3
0
        public IHttpActionResult DeletetypeFactory(int id)
        {
            typeFactory typeFactory = db.typeFactories.Find(id);

            if (typeFactory == null)
            {
                return(NotFound());
            }

            db.typeFactories.Remove(typeFactory);
            db.SaveChanges();

            return(Ok(ToViewModel(typeFactory)));
        }
        private FactoryViewModel ToViewModel(Factory c)
        {
            catFactory catFactory = c.catFactory;

            if (catFactory == null)
            {
                catFactory = db.catFactories.Find(c.Cat);
            }
            typeFactory typeFactory = c.typeFactory;

            if (typeFactory == null)
            {
                typeFactory = db.typeFactories.Find(c.Type);
            }
            catPay catPay = c.catPay;

            if (catPay == null)
            {
                catPay = db.catPays.Find(c.Pay);
            }
            catCurrency catCurrency = c.catCurrency;

            if (catCurrency == null)
            {
                catCurrency = db.catCurrencies.Find(c.Currency);
            }

            return(new FactoryViewModel {
                Id = c.Id, Cat = c.Cat,
                CatName = catFactory == null ? "" : catFactory.Name,
                TypeName = typeFactory == null ? "": typeFactory.Name,
                PayName = catPay == null ? "" : catPay.Name,
                CurrencyName = catCurrency == null ? "" : catCurrency.Name,
                Type = c.Type, NO = c.NO, Name = c.Name, Sname = c.Sname, Unid = c.Unid, Contact1 = c.Contact1, Contact2 = c.Contact2, Email1 = c.Email1, Email2 = c.Email2, Email3 = c.Email3, Telephone1 = c.Telephone1, Telephone2 = c.Telephone2, Telephone3 = c.Telephone3, Website = c.Website, Fax = c.Fax, Address = c.Address, Shipaddr = c.Shipaddr, Invoiceaddr = c.Invoiceaddr, Pay = c.Pay, Currency = c.Currency, Lasttrade = c.Lasttrade, Note = c.Note, TimestampString = Convert.ToBase64String(c.Timestamp)
            });
        }
Example #5
0
 private TypeFactoryViewModel ToViewModel(typeFactory c)
 {
     return(new TypeFactoryViewModel {
         Id = c.Id, No = c.No, Name = c.Name, TimestampString = Convert.ToBase64String(c.Timestamp)
     });
 }