public void Put(string id, [FromBody] Model.Component value)
        {
            var db = LiteDBClient.Database;

            value._id = id;
            db.GetCollection <Model.Component>(LiteDBClient.Components).Upsert(value);
        }
示例#2
0
        static StackObject *AddComponent_3(ILIntepreter __intp, StackObject *__esp, List <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            Model.Component component = (Model.Component) typeof(Model.Component).CheckCLRTypes(__domain, StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Model.Entity instance_of_this_method;
            instance_of_this_method = (Model.Entity) typeof(Model.Entity).CheckCLRTypes(__domain, StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.AddComponent(component);

            return(__ret);
        }
示例#3
0
 public ComponentWrapper(Model.Component model)
 {
     Model = model;
 }
示例#4
0
        // POST: api/Component
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Component component = new Model.Component();

                string  message         = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json            = JObject.Parse(message);
                JObject cmpDetails      = (JObject)json["component"];
                JArray  supplierDetails = (JArray)json["suppliers"];

                int key = db.Components.Count() == 0 ? 1 : (from t in db.Components
                                                            orderby t.Component_ID descending
                                                            select t.Component_ID).First() + 1;

                component.Component_ID = key;
                component.Quantity     = (int)cmpDetails["Quantity"];
                component.Unit_Price   = (decimal)cmpDetails["Unit_Price"];
                component.Description  = (string)cmpDetails["Description"];
                component.Dimension    = (string)cmpDetails["Dimension"];
                component.Name         = (string)cmpDetails["Name"];
                component.Min_Stock    = (int)cmpDetails["Min_Stock"];

                string errorString = "false|";
                bool   error       = false;

                if ((from t in db.Components
                     where t.Name == component.Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Component name entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Components.Add(component);

                foreach (JObject supplier in supplierDetails)
                {
                    Component_Supplier cs = new Component_Supplier();
                    cs.Component_ID = key;
                    cs.Supplier_ID  = (int)supplier["Supplier_ID"];
                    cs.is_preferred = Convert.ToBoolean(Convert.ToInt32(supplier["Is_Prefered"]));
                    cs.unit_price   = (decimal)supplier["unit_price"];

                    db.Component_Supplier.Add(cs);
                }

                db.SaveChanges();
                return("true|Component #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "ComponentController POST");
                return("false|An error has occured adding the Component to the system.");
            }
        }
        public void Post([FromBody] Model.Component value)
        {
            var db = LiteDBClient.Database;

            db.GetCollection <Model.Component>(LiteDBClient.Components).Upsert(value);
        }