예제 #1
0
        public Dictionary <string, object> addWorkOrder(List <WorkOrder> workOrders)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            int CompanyID   = Convert.ToInt32(HttpContext.Current.Session["cid_SCL_account"].ToString());
            int LoginUserID = Convert.ToInt32(HttpContext.Current.Session["am_userid"].ToString());

            using (var tran = gc.db.Database.BeginTransaction())
            {
                try
                {
                    DateTime             dt      = DateTime.Now;
                    int                  count   = gc.db.SCL_WorkOrder_Master.Count();
                    string               wo_ref  = string.Format("WO{0}{1:D5}", dt.ToString("yyyyMMdd"), count + 1);
                    SCL_WorkOrder_Master _Master = new SCL_WorkOrder_Master();
                    _Master.WO_REFERENCE = wo_ref;
                    _Master.WO_DATE      = dt;
                    _Master.USER_ID      = LoginUserID;
                    _Master.COMPANY_ID   = CompanyID;
                    _Master.CREATED_BY   = LoginUserID;
                    _Master.CREATED_DATE = dt;
                    gc.db.SCL_WorkOrder_Master.Add(_Master);
                    int wm = gc.db.SaveChanges();

                    if (wm > 0)
                    {
                        foreach (WorkOrder item in workOrders)
                        {
                            SCL_WorkOrder_Details _Details = new SCL_WorkOrder_Details();
                            _Details.WO_REFERENCE = wo_ref;
                            _Details.COMPANY_ID   = CompanyID;
                            _Details.USER_ID      = LoginUserID;
                            _Details.COMPLAINT_ID = item.COMPLAINT_ID;
                            _Details.JC_REFERENCE = item.JC_REFERENCE;
                            _Details.WODID        = _Master.WOID;
                            _Details.WO_DATE      = dt;
                            _Details.CREATED_DATE = dt;
                            gc.db.SCL_WorkOrder_Details.Add(_Details);
                            if (gc.db.SaveChanges() > 0)
                            {
                                var _comp     = "";
                                var auto_comp = "";
                                SCL_Mobile_Complaints       comp   = gc.db.SCL_Mobile_Complaints.Where(x => x.ID == item.COMPLAINT_ID).FirstOrDefault();
                                SCL_Mobile_Complaints_Audit _Audit = new SCL_Mobile_Complaints_Audit();
                                if (comp.automatic_complaint == null)
                                {
                                    auto_comp = "";
                                }
                                else
                                {
                                    auto_comp = comp.automatic_complaint;
                                }
                                if (comp.Comments == null)
                                {
                                    _comp = "";
                                }
                                else
                                {
                                    _comp = comp.Comments;
                                }
                                _Audit.Complaint_ID          = comp.ID;
                                _Audit.Complaint_ReferenceNo = comp.Complaint_ReferenceNo;
                                _Audit.Complaint_Date        = comp.Complaint_Date.ToString();
                                _Audit.Category_Id           = comp.Category_Id;
                                _Audit.Category_Desc         = comp.Category_Desc;
                                _Audit.SubCategory_Desc      = comp.SubCategory_Desc;
                                _Audit.SubCategory_Id        = comp.SubCategory_Id;
                                _Audit.Dept_Desc             = comp.Dept_Desc;
                                _Audit.CreatedDate           = comp.CreatedDate;
                                _Audit.ModifiedBy            = CompanyID.ToString();
                                _Audit.ModifiedDate          = DateTime.Now;
                                _Audit.ComplaintStatus       = comp.ComplaintStatus;
                                _Audit.Lattitude             = comp.Lattitude;
                                _Audit.Longitude             = comp.Longitude;
                                _Audit.automatic_complaint   = auto_comp;
                                _Audit.userID   = comp.userID;
                                _Audit.Comments = _comp;
                                gc.db.SCL_Mobile_Complaints_Audit.Add(_Audit);
                                int xx = gc.db.SaveChanges();
                                if (xx == 1)
                                {
                                    comp.ComplaintStatus = "Allocated";
                                    comp.ModifiedBy      = CompanyID + "";
                                    comp.ModifiedDate    = DateTime.Now;
                                    int n = gc.db.SaveChanges();

                                    if (n > 0)
                                    {
                                        SCL_ComplaintsAllocated comp_Allocated = new SCL_ComplaintsAllocated();
                                        comp_Allocated.CompID          = item.COMPLAINT_ID;
                                        comp_Allocated.CompanyID       = CompanyID;
                                        comp_Allocated.UserID          = comp.AllocateduserID;
                                        comp_Allocated.Status          = "Allocated";
                                        comp_Allocated.CreatedBy       = CompanyID;
                                        comp_Allocated.CreatedDateTime = DateTime.Now;
                                        gc.db.SCL_ComplaintsAllocated.Add(comp_Allocated);
                                        int c = gc.db.SaveChanges();
                                        if (c > 0)
                                        {
                                            SCL_JobCards jobs = gc.db.SCL_JobCards.Where(x => x.COMPLAINT_ID == item.COMPLAINT_ID).FirstOrDefault();
                                            jobs.COMP_STATUS   = "Allocated";
                                            jobs.MODIFIED_BY   = CompanyID;
                                            jobs.MODIFIED_DATE = DateTime.Now;
                                            int j = gc.db.SaveChanges();
                                            if (j > 0)
                                            {
                                            }
                                            else
                                            {
                                                tran.Rollback();
                                                dic.Add("error", "Update Fail");
                                            }
                                        }
                                        else
                                        {
                                            tran.Rollback();
                                            dic.Add("error", "Update Fail");
                                        }
                                    }
                                    else
                                    {
                                        tran.Rollback();
                                        dic.Add("error", "Update Fail");
                                    }
                                }
                            }
                        }
                    }


                    tran.Commit();
                    dic.Add("success", "success");
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    tran.Rollback();
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    dic.Add("error", raise.Message);
                }
            }
            return(dic);
        }
예제 #2
0
        public Dictionary <string, object> AssignedComplaintUser(int ID, int UserID, string Comments)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            int CompanyID = Convert.ToInt32(HttpContext.Current.Session["cid_SCL_account"].ToString());

            using (var tran = gc.db.Database.BeginTransaction())
            {
                try
                {
                    var Status    = "Assigned";
                    var auto_comp = "";
                    SCL_Mobile_Complaints       comp   = gc.db.SCL_Mobile_Complaints.Where(x => x.ID == ID && x.CompanyID == CompanyID).FirstOrDefault();
                    SCL_Mobile_Complaints_Audit _Audit = new SCL_Mobile_Complaints_Audit();

                    if (comp.automatic_complaint == null)
                    {
                        auto_comp = "";
                    }
                    else
                    {
                        auto_comp = comp.automatic_complaint;
                    }
                    _Audit.Complaint_ID          = comp.ID;
                    _Audit.Complaint_ReferenceNo = comp.Complaint_ReferenceNo;
                    _Audit.Complaint_Date        = comp.Complaint_Date.ToString();
                    _Audit.Category_Id           = comp.Category_Id;
                    _Audit.Category_Desc         = comp.Category_Desc;
                    _Audit.SubCategory_Desc      = comp.SubCategory_Desc;
                    _Audit.SubCategory_Id        = comp.SubCategory_Id;
                    _Audit.Dept_Desc             = comp.Dept_Desc;
                    _Audit.CreatedDate           = comp.CreatedDate;
                    _Audit.ModifiedBy            = CompanyID.ToString();
                    _Audit.ModifiedDate          = DateTime.Now;
                    _Audit.ComplaintStatus       = comp.ComplaintStatus;
                    _Audit.Lattitude             = comp.Lattitude;
                    _Audit.Longitude             = comp.Longitude;
                    _Audit.automatic_complaint   = auto_comp;
                    _Audit.userID = comp.userID;
                    gc.db.SCL_Mobile_Complaints_Audit.Add(_Audit);
                    int xx = gc.db.SaveChanges();
                    if (xx == 1)
                    {
                        comp.ComplaintStatus = Status;
                        comp.ModifiedBy      = CompanyID + "";
                        comp.ModifiedDate    = DateTime.Now;
                        comp.AllocateduserID = UserID;
                        comp.Comments        = Comments;
                        comp.JC_REF          = "JC_" + comp.Category_Id + "" + ID;
                        int n = gc.db.SaveChanges();

                        if (n > 0)
                        {
                            SCL_ComplaintsAllocated comp_Allocated = new SCL_ComplaintsAllocated();
                            comp_Allocated.CompID          = ID;
                            comp_Allocated.CompanyID       = CompanyID;
                            comp_Allocated.UserID          = UserID;
                            comp_Allocated.Status          = "Assigned";
                            comp_Allocated.CreatedBy       = CompanyID;
                            comp_Allocated.CreatedDateTime = DateTime.Now;
                            comp_Allocated.Comments        = Comments;
                            gc.db.SCL_ComplaintsAllocated.Add(comp_Allocated);
                            int c = gc.db.SaveChanges();
                            if (c > 0)
                            {
                                if (_Audit.ComplaintStatus.Equals("Reallocate") || _Audit.ComplaintStatus.Equals("Redirect"))
                                {
                                    if (gc.db.SCL_JobCards.Any(x => x.COMPLAINT_ID == ID))
                                    {
                                        SCL_JobCards jobs = gc.db.SCL_JobCards.Where(x => x.COMPLAINT_ID == ID).FirstOrDefault();

                                        jobs.USER_ID       = UserID;
                                        jobs.COMP_STATUS   = comp.ComplaintStatus;
                                        jobs.COMP_COMMENTS = Comments;
                                        jobs.MODIFIED_BY   = CompanyID;
                                        jobs.MODIFIED_DATE = DateTime.Now;
                                        gc.db.SaveChanges();
                                        tran.Commit();
                                        dic.Add("JCREF", jobs.JC_REFERENCE);
                                        dic.Add("success", "success");
                                    }
                                    else
                                    {
                                        SCL_JobCards _JOB = new SCL_JobCards();
                                        _JOB.JC_REFERENCE   = "JC_" + comp.Category_Id + "" + ID;
                                        _JOB.JC_DATE        = DateTime.Now;
                                        _JOB.COMP_REFERENCE = comp.Complaint_ReferenceNo;
                                        _JOB.COMP_DATE      = comp.CreatedDate;
                                        _JOB.COMPANY_ID     = CompanyID;
                                        _JOB.COMPLAINT_ID   = ID;
                                        _JOB.USER_ID        = UserID;
                                        _JOB.DEPARTMENT     = comp.Dept_Desc;
                                        _JOB.CATEGORY       = comp.Category_Desc;
                                        _JOB.SUB_CATEGORY   = comp.SubCategory_Desc;
                                        _JOB.ADDRESS        = comp.Address;
                                        _JOB.COMP_STATUS    = comp.ComplaintStatus;
                                        _JOB.COMP_COMMENTS  = Comments;
                                        _JOB.CREATED_BY     = CompanyID;
                                        _JOB.CREATED_DATE   = DateTime.Now;
                                        gc.db.SCL_JobCards.Add(_JOB);
                                        gc.db.SaveChanges();
                                        tran.Commit();
                                        dic.Add("JCREF", _JOB.JC_REFERENCE);
                                        dic.Add("success", "success");
                                    }
                                }
                                else
                                {
                                    SCL_JobCards _JOB = new SCL_JobCards();
                                    _JOB.JC_REFERENCE   = "JC_" + comp.Category_Id + "" + ID;
                                    _JOB.JC_DATE        = DateTime.Now;
                                    _JOB.COMP_REFERENCE = comp.Complaint_ReferenceNo;
                                    _JOB.COMP_DATE      = comp.CreatedDate;
                                    _JOB.COMPANY_ID     = CompanyID;
                                    _JOB.COMPLAINT_ID   = ID;
                                    _JOB.USER_ID        = UserID;
                                    _JOB.DEPARTMENT     = comp.Dept_Desc;
                                    _JOB.CATEGORY       = comp.Category_Desc;
                                    _JOB.SUB_CATEGORY   = comp.SubCategory_Desc;
                                    _JOB.ADDRESS        = comp.Address;
                                    _JOB.COMP_STATUS    = comp.ComplaintStatus;
                                    _JOB.COMP_COMMENTS  = Comments;
                                    _JOB.CREATED_BY     = CompanyID;
                                    _JOB.CREATED_DATE   = DateTime.Now;
                                    gc.db.SCL_JobCards.Add(_JOB);
                                    gc.db.SaveChanges();
                                    tran.Commit();
                                    dic.Add("JCREF", _JOB.JC_REFERENCE);
                                    dic.Add("success", "success");
                                }
                            }
                            else
                            {
                                tran.Rollback();
                                dic.Add("error", "Failed!");
                            }
                        }
                        else
                        {
                            tran.Rollback();
                            dic.Add("error", "Failed!");
                        }
                    }
                    else
                    {
                        tran.Rollback();
                        dic.Add("error", "No results found!");
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    tran.Rollback();
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    dic.Add("error", raise.Message);
                }
            }
            return(dic);
        }
예제 #3
0
        public Dictionary <string, object> updateJobcardStatus(JobcardUpdatedData jobData)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            int CompanyID = Convert.ToInt32(HttpContext.Current.Session["cid_SCL_account"].ToString());

            using (var tran = gc.db.Database.BeginTransaction())
            {
                try
                {
                    var _comp     = "";
                    var auto_comp = "";
                    SCL_Mobile_Complaints       comp   = gc.db.SCL_Mobile_Complaints.Where(x => x.ID == jobData.ID).FirstOrDefault();
                    SCL_Mobile_Complaints_Audit _Audit = new SCL_Mobile_Complaints_Audit();
                    if (comp != null)
                    {
                        auto_comp = comp.automatic_complaint;
                        _comp     = comp.Comments;
                    }

                    _Audit.Complaint_ID          = comp.ID;
                    _Audit.Complaint_ReferenceNo = comp.Complaint_ReferenceNo;
                    _Audit.Complaint_Date        = comp.Complaint_Date.ToString();
                    _Audit.Category_Id           = comp.Category_Id;
                    _Audit.Category_Desc         = comp.Category_Desc;
                    _Audit.SubCategory_Desc      = comp.SubCategory_Desc;
                    _Audit.SubCategory_Id        = comp.SubCategory_Id;
                    _Audit.Dept_Desc             = comp.Dept_Desc;
                    _Audit.CreatedDate           = comp.CreatedDate;
                    _Audit.ModifiedBy            = CompanyID.ToString();
                    _Audit.ModifiedDate          = DateTime.Now;
                    _Audit.ComplaintStatus       = comp.ComplaintStatus;
                    _Audit.Lattitude             = comp.Lattitude;
                    _Audit.Longitude             = comp.Longitude;
                    _Audit.automatic_complaint   = auto_comp;
                    _Audit.userID   = comp.userID;
                    _Audit.Comments = _comp;
                    gc.db.SCL_Mobile_Complaints_Audit.Add(_Audit);
                    int xx = gc.db.SaveChanges();
                    if (xx == 1)
                    {
                        comp.ComplaintStatus = jobData.compStatus;
                        comp.ModifiedBy      = CompanyID + "";
                        comp.ModifiedDate    = DateTime.Now;
                        comp.Comments        = jobData.Comments;
                        int n = gc.db.SaveChanges();

                        if (n > 0)
                        {
                            SCL_ComplaintsAllocated comp_Allocated = new SCL_ComplaintsAllocated();
                            comp_Allocated.CompID          = jobData.ID;
                            comp_Allocated.CompanyID       = CompanyID;
                            comp_Allocated.UserID          = comp.AllocateduserID;
                            comp_Allocated.Status          = jobData.compStatus;
                            comp_Allocated.CreatedBy       = CompanyID;
                            comp_Allocated.CreatedDateTime = DateTime.Now;
                            comp_Allocated.Comments        = jobData.Comments;
                            gc.db.SCL_ComplaintsAllocated.Add(comp_Allocated);
                            int c = gc.db.SaveChanges();
                            if (c > 0)
                            {
                                SCL_JobCards jobs = gc.db.SCL_JobCards.Where(x => x.COMPLAINT_ID == jobData.ID).FirstOrDefault();
                                jobs.COMP_STATUS   = jobData.compStatus;
                                jobs.COMP_COMMENTS = jobData.Comments;
                                jobs.MODIFIED_BY   = CompanyID;
                                jobs.MODIFIED_DATE = DateTime.Now;
                                if (jobData.PStatus.Equals("Assigned") || jobData.PStatus.Equals("Allocated"))
                                {
                                    jobs.START_DATE    = jobData.StartDate;
                                    jobs.END_DATE      = jobData.EndDate;
                                    jobs.VEHICLE_NO    = jobData.VehicalNo;
                                    jobs.JOB_DISTANCE  = jobData.JobDistance;
                                    jobs.SERVICE_HOURS = jobData.ServiceHours;
                                }

                                int j = gc.db.SaveChanges();
                                if (j > 0)
                                {
                                    tran.Commit();
                                    dic.Add("success", "success");
                                }
                                else
                                {
                                    tran.Rollback();
                                    dic.Add("error", "Update Failed!");
                                }
                            }
                            else
                            {
                                tran.Rollback();
                                dic.Add("error", "Update Failed!");
                            }
                        }
                        else
                        {
                            tran.Rollback();
                            dic.Add("error", "Update Failed!");
                        }
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    tran.Rollback();
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    dic.Add("error", raise.Message);
                }
            }
            return(dic);
        }