Пример #1
0
        public ActionResult Index(string jobsid)
        {
            if (jobsid != null && jobsid.Trim() != "")
            {
                var check_date = db.tb_jobs.Where(w => w.service_order_no == jobsid && w.is_delete == 0).FirstOrDefault();
                if (check_date != null)
                {
                    var engineer_data = (from e in db.tb_engineer where e.is_delete == 0 && check_date.engineer_id == e.id select e);
                    var store_data    = db.tb_store.Where(w => w.id == engineer_data.FirstOrDefault().site_id&& w.is_delete == 0).FirstOrDefault();
                    if (Convert.ToDateTime(check_date.appointment_datetime).Date == DateTime.Today.Date && check_date.appointment_to_datetime != null && store_data != null)
                    {
                        var data = (from j in db.tb_jobs
                                    where j.is_delete == 0 && j.service_order_no == jobsid
                                    select new index
                        {
                            //phone_mobile = j.phone_mobile,
                            service_order_no = j.service_order_no,
                            appointment_datetime = j.appointment_datetime,
                            appointment_to_datetime = j.appointment_to_datetime,
                            customer_lat = j.customer_lat,
                            customer_long = j.customer_long,
                            customer_fullname = j.customer_fullname,
                            customer_mobile = j.phone_mobile,
                            status_job = j.status_job,
                            engi = engineer_data.FirstOrDefault(),
                            phone_office = store_data.tel1 != null ? store_data.tel1 : store_data.tel2 != null ? store_data.tel2 : store_data.tel3
                        }).FirstOrDefault();

                        if (data.status_job != 2 && data.status_job != 4)
                        {
                            ViewData["job_engi"] = data;
                            StandardController service_con = new StandardController();
                            string             key_azure   = service_con.GetKeyAzure();
                            ViewData["Key_Azure"] = key_azure;

                            //get IP , Stamp
                            var ip_client = byi_common.common.GetIPAddress();
                            check_date.ip_customer   = ip_client;
                            check_date.date_customer = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zone);
                            db.tb_jobs.AddOrUpdate(check_date);
                            db.SaveChanges();

                            return(View());
                        }
                        return(View("Error"));
                    }
                    return(View("Error"));
                }
                return(View("Error"));
            }
            return(View("Error"));
        }
        public ActionResult edit(string id)
        {
            GetDataFromDb();

            Guid check_Guid;
            bool isValid = Guid.TryParse(id, out check_Guid);

            if (isValid)
            {
                Guid newGuid = Guid.Parse(id);
                if (User.IsInRole("admin"))
                {
                    var obj_list_en = (from e in db.tb_engineer
                                       where e.en_guid == newGuid && e.is_delete == 0
                                       select e).FirstOrDefault();

                    if (obj_list_en != null)
                    {
                        ViewData["Data"] = obj_list_en;
                    }
                    else
                    {
                        var url = ConfigurationManager.AppSettings["Base_URL"].ToString() + "engineer/all";
                        Response.Redirect(url);
                    }
                }
                else
                {
                    var getName = User.Identity.Name;

                    var  CheckUser   = Membership.GetUser(getName).ProviderUserKey;
                    Guid convertGuid = new Guid(CheckUser.ToString());
                    var  idStore     = db.tb_mapping_store.Where(w => w.account_guid == convertGuid).Select(s => s.site_id).FirstOrDefault();

                    var obj_list_en = (from e in db.tb_engineer
                                       where e.site_id == idStore && e.en_guid == newGuid && e.is_delete == 0
                                       select e).FirstOrDefault();

                    if (obj_list_en != null)
                    {
                        ViewData["Data"] = obj_list_en;
                    }
                    else
                    {
                        //wait redirect
                        var url = ConfigurationManager.AppSettings["Base_URL"].ToString() + "engineer/all";
                        Response.Redirect(url);
                    }
                }
            }
            else
            {
                var url = ConfigurationManager.AppSettings["Base_URL"].ToString() + "engineer/all";
                Response.Redirect(url);
            }

            ViewData["Azure_Path"] = ConfigurationManager.AppSettings["Azure_url"];
            StandardController service_con = new StandardController();
            string             key_azure   = service_con.GetKeyAzure();

            ViewData["Key_Azure"] = key_azure;

            return(View());
        }