예제 #1
0
        public dynamic SaveMobileBowser([FromBody] Newtonsoft.Json.Linq.JObject param)
        {
            dynamic objParamInfo = param;
            dynamic objresponse  = null;
            // int CustomerID = Int32.Parse(_tokenData.UserID);
            int    CustomerID = objParamInfo.CustomerID;
            string Message    = "";
            int    BowserID   = objParamInfo.BowserID != null ? objParamInfo.BowserID : 0;
            string bowsername = objParamInfo.bowsername;
            string carno      = objParamInfo.carno;
            string ownerName  = objParamInfo.ownername;
            string address    = objParamInfo.address;
            string phone      = objParamInfo.phone;

            // string CompanyID = _tokenData.CompanyID;
            try
            {
                string customerId = _session.GetString("LoginUserID");
                // if(CustomerID == customerId)
                if (Convert.ToString(CustomerID) == customerId)
                {
                    var bobj = _repositoryWrapper.Bowser.FindByID(BowserID);
                    if (bobj != null)
                    {
                        bobj.bowserName = objParamInfo.bowsername;
                        bobj.carNo      = objParamInfo.carno;
                        bobj.ownerName  = objParamInfo.ownername;
                        bobj.address    = objParamInfo.address;
                        bobj.phone      = objParamInfo.phone;
                        //bobj.status = objParamInfo.status;
                        bobj.createuser   = CustomerID;
                        bobj.user_type    = true;
                        bobj.modifieddate = System.DateTime.Now;
                        bobj.inactive     = true;
                        _repositoryWrapper.Bowser.Update(bobj);
                        // _repositoryWrapper.EventLog.Update(bobj);
                        if (objParamInfo.deleteitem.Count > 0)
                        {
                            for (int i = 0; i < objParamInfo.deleteitem.Count; i++)
                            {
                                int compartmentID = objParamInfo.deleteitem[i].ID;
                                var updateobj     = _repositoryWrapper.Compartment.FindByID(compartmentID);
                                if (updateobj != null)
                                {
                                    updateobj.inactive     = false;
                                    updateobj.modifieddate = System.DateTime.Now;
                                    _repositoryWrapper.Compartment.Update(updateobj);
                                    // _repositoryWrapper.EventLog.Update(updateobj);
                                }
                            }
                        }
                        for (int i = 0; i < objParamInfo.item.Count; i++)
                        {
                            int compartmentID = objParamInfo.item[i].ID;
                            var updateobj     = _repositoryWrapper.Compartment.FindByID(compartmentID);
                            if (updateobj != null)
                            {
                                updateobj.bowserID     = BowserID;
                                updateobj.calibration  = objParamInfo.item[i].Calibration;
                                updateobj.capacity     = objParamInfo.item[i].Size;
                                updateobj.name         = objParamInfo.item[i].Name;
                                updateobj.inactive     = true;
                                updateobj.modifieddate = System.DateTime.Now;
                                _repositoryWrapper.Compartment.Update(updateobj);
                                // _repositoryWrapper.EventLog.Update(updateobj);
                            }
                            else
                            {
                                var newcobj = new Compartment();
                                newcobj.bowserID     = BowserID;
                                newcobj.calibration  = objParamInfo.item[i].Calibration;
                                newcobj.capacity     = objParamInfo.item[i].Size;
                                newcobj.name         = objParamInfo.item[i].Name;
                                newcobj.inactive     = true;
                                newcobj.modifieddate = System.DateTime.Now;
                                _repositoryWrapper.Compartment.Create(newcobj);
                                // _repositoryWrapper.EventLog.Insert(newcobj);
                            }
                        }
                        Message = "Update Successfully! ";
                    }
                    else
                    {
                        var newobj = new Bowser();
                        newobj.bowserName   = objParamInfo.bowsername;
                        newobj.carNo        = objParamInfo.carno;
                        newobj.ownerName    = objParamInfo.ownername;
                        newobj.address      = objParamInfo.address;
                        newobj.phone        = objParamInfo.phone;
                        newobj.modifieddate = System.DateTime.Now;
                        newobj.inactive     = true;
                        newobj.status       = 0;
                        newobj.createuser   = CustomerID;
                        newobj.user_type    = true;
                        _repositoryWrapper.Bowser.Create(newobj);
                        BowserID = newobj.bowserID;

                        for (int i = 0; i < objParamInfo.item.Count; i++)
                        {
                            var newcobj = new Compartment();
                            newcobj.bowserID     = BowserID;
                            newcobj.calibration  = objParamInfo.item[i].Calibration;
                            newcobj.capacity     = objParamInfo.item[i].Size;
                            newcobj.name         = objParamInfo.item[i].Name;
                            newcobj.inactive     = true;
                            newcobj.modifieddate = System.DateTime.Now;
                            _repositoryWrapper.Compartment.Create(newcobj);
                        }
                        Message = "Save Successfully!";
                    }

                    objresponse = new { status = 1, messages = Message };
                }
                else
                {
                    Message     = "Sorry! Please Try Again ";
                    objresponse = new { status = 0, messages = Message };
                }
            }
            catch (ValidationException ex)
            {
                // objresponse = new { error = ex.Message };
                _repositoryWrapper.EventLog.Error("", ex.Message);
                objresponse = new { status = 0, messages = "Oh! Something Wrong.Please try again!" };
            }

            return(objresponse);
        }
예제 #2
0
        public dynamic SaveBowser([FromBody] Newtonsoft.Json.Linq.JObject param)
        {
            dynamic obj         = param;
            dynamic objresponse = null;
            int     LoginID     = Int32.Parse(_tokenData.UserID);
            int     BowserID    = obj.BowserID != null ? obj.BowserID : 0;
            string  CompanyID   = _tokenData.CompanyID;

            try
            {
                var bobj = _repositoryWrapper.Bowser.FindByID(BowserID);
                if (bobj != null)
                {
                    bobj.bowserName = obj.bowsername;
                    bobj.carNo      = obj.carno;
                    bobj.ownerName  = obj.ownername;
                    bobj.address    = obj.address;
                    bobj.phone      = obj.phone;
                    // bobj.status = obj.status;
                    bobj.user_type    = false;
                    bobj.createuser   = LoginID;
                    bobj.modifieddate = System.DateTime.Now;
                    bobj.inactive     = true;
                    _repositoryWrapper.Bowser.Update(bobj);
                    _repositoryWrapper.EventLog.Update(bobj);
                    if (obj.deleteitem.Count > 0)
                    {
                        for (int i = 0; i < obj.deleteitem.Count; i++)
                        {
                            int compartmentID = obj.deleteitem[i].ID;
                            var updateobj     = _repositoryWrapper.Compartment.FindByID(compartmentID);
                            if (updateobj != null)
                            {
                                updateobj.inactive     = false;
                                updateobj.modifieddate = System.DateTime.Now;
                                _repositoryWrapper.Compartment.Update(updateobj);
                                _repositoryWrapper.EventLog.Update(updateobj);
                            }
                        }
                    }
                    for (int i = 0; i < obj.item.Count; i++)
                    {
                        int compartmentID = obj.item[i].ID;
                        var updateobj     = _repositoryWrapper.Compartment.FindByID(compartmentID);
                        if (updateobj != null)
                        {
                            updateobj.bowserID     = BowserID;
                            updateobj.calibration  = obj.item[i].Calibration;
                            updateobj.capacity     = obj.item[i].Size;
                            updateobj.name         = obj.item[i].Name;
                            updateobj.inactive     = true;
                            updateobj.modifieddate = System.DateTime.Now;
                            _repositoryWrapper.Compartment.Update(updateobj);
                            _repositoryWrapper.EventLog.Update(updateobj);
                        }
                        else
                        {
                            var newcobj = new Compartment();
                            newcobj.bowserID     = BowserID;
                            newcobj.calibration  = obj.item[i].Calibration;
                            newcobj.capacity     = obj.item[i].Size;
                            newcobj.name         = obj.item[i].Name;
                            newcobj.inactive     = true;
                            newcobj.modifieddate = System.DateTime.Now;
                            _repositoryWrapper.Compartment.Create(newcobj);
                            _repositoryWrapper.EventLog.Insert(newcobj);
                        }
                    }
                }
                else
                {
                    var newobj = new Bowser();
                    newobj.bowserName   = obj.bowsername;
                    newobj.carNo        = obj.carno;
                    newobj.ownerName    = obj.ownername;
                    newobj.address      = obj.address;
                    newobj.phone        = obj.phone;
                    newobj.user_type    = false;
                    newobj.createuser   = LoginID;
                    newobj.modifieddate = System.DateTime.Now;
                    newobj.inactive     = true;
                    _repositoryWrapper.Bowser.Create(newobj);
                    _repositoryWrapper.EventLog.Insert(newobj);
                    BowserID = newobj.bowserID;

                    for (int i = 0; i < obj.item.Count; i++)
                    {
                        int compartmentID = obj.item[i].ID;
                        var newcobj       = new Compartment();
                        newcobj.bowserID     = BowserID;
                        newcobj.calibration  = obj.item[i].Calibration;
                        newcobj.capacity     = obj.item[i].Size;
                        newcobj.name         = obj.item[i].Name;
                        newcobj.inactive     = true;
                        newcobj.modifieddate = System.DateTime.Now;
                        _repositoryWrapper.Compartment.Create(newcobj);
                        _repositoryWrapper.EventLog.Insert(newcobj);
                    }
                }

                objresponse = new { data = BowserID };
            }
            catch (ValidationException vex)
            {
                _repositoryWrapper.EventLog.Error("Bowser Controller/ Save Bowser", vex.Message);
                objresponse = new { data = 0, error = vex.ValidationResult.ErrorMessage };
                Console.WriteLine(vex.Message);
            }

            return(objresponse);
        }