Exemplo n.º 1
0
        public IHttpActionResult PostcatFactory(CatFactoryViewModel Cat_FactoryView_Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            catFactory catFactory_db;

            try
            {
                catFactory_db = new catFactory {
                    Id = Cat_FactoryView_Model.Id, No = Cat_FactoryView_Model.No, Name = Cat_FactoryView_Model.Name
                };
                db.catFactories.Add(catFactory_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 = catFactory_db.Id }, ToViewModel(catFactory_db)));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetcatFactory(int id)
        {
            catFactory catFactory = db.catFactories.Find(id);

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

            return(Ok(ToViewModel(catFactory)));
        }
Exemplo n.º 3
0
        public IHttpActionResult DeletecatFactory(int id)
        {
            catFactory catFactory = db.catFactories.Find(id);

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

            db.catFactories.Remove(catFactory);
            db.SaveChanges();

            return(Ok(ToViewModel(catFactory)));
        }
        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)
            });
        }
Exemplo n.º 5
0
 private CatFactoryViewModel ToViewModel(catFactory c)
 {
     return(new CatFactoryViewModel {
         Id = c.Id, No = c.No, Name = c.Name, TimestampString = Convert.ToBase64String(c.Timestamp)
     });
 }