示例#1
0
    public PagedList <MedicalFacilityModel> GetAllMedicalFacilitiesPaginated(int skip, int take, string order, string where)
    {
        var medicalFacilities = new List <MedicalFacilityModel>();
        var orderBy           = string.IsNullOrEmpty(order) ? " order by mf.created_on desc " : order;
        var query             = "select mf.*, cm.city_name from medical_facility_master mf, city_master cm where mf.city_id = cm.city_id and mf.is_active='y' " + where + orderBy + " limit " + take + " offset " + skip;
        var rows = new DataAccessManager().ExecuteSelectQuery(query);

        if (rows != null && rows.Count > 0)
        {
            foreach (DataRow r in rows)
            {
                var medicalFacility = new MedicalFacilityModel();
                var props           = typeof(MedicalFacilityModel).GetProperties();

                foreach (var prop in props)
                {
                    var ignore = Attribute.IsDefined(prop, typeof(IgnoreSelect));
                    if (!ignore)
                    {
                        var    attribute   = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true).Cast <DisplayNameAttribute>().Single();
                        string displayName = attribute.DisplayName;

                        var    value = r[displayName];
                        var    pType = prop.PropertyType;
                        object v     = null;
                        if (pType == typeof(bool))
                        {
                            v = value.ToString() == "y";
                        }
                        else
                        {
                            v = value == null ? null : value;
                        }

                        var variable = prop.SetMethod;

                        if (!r.IsNull(displayName))
                        {
                            variable.Invoke(medicalFacility, new object[] { v });
                        }
                    }
                }
                medicalFacilities.Add(medicalFacility);
            }
        }
        query = "select count(*) from medical_facility_master mf, city_master cm where mf.city_id = cm.city_id and mf.is_active='y' " + where;
        var totalCount = new DataAccessManager().ExecuteScalar(query);
        var count      = totalCount != null?int.Parse(totalCount.ToString()) : 0;

        var result = new PagedList <MedicalFacilityModel>()
        {
            TotalCount = count, Data = medicalFacilities
        };

        return(result);
    }
示例#2
0
    public List <MedicalFacilityModel> GetAllMedicalFacilities()
    {
        var medicalFacilities = new List <MedicalFacilityModel>();

        var query = "select * from medical_facility_master where is_active='y' order by created_on desc";
        var rows  = new DataAccessManager().ExecuteSelectQuery(query);

        if (rows != null && rows.Count > 0)
        {
            foreach (DataRow r in rows)
            {
                var medicalFacility = new MedicalFacilityModel();
                var props           = typeof(MedicalFacilityModel).GetProperties();

                foreach (var prop in props)
                {
                    var ignore = Attribute.IsDefined(prop, typeof(IgnoreInsert));
                    if (!ignore)
                    {
                        var    attribute   = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true).Cast <DisplayNameAttribute>().Single();
                        string displayName = attribute.DisplayName;

                        var    value = r[displayName];
                        var    pType = prop.PropertyType;
                        object v     = null;
                        if (pType == typeof(bool))
                        {
                            v = value.ToString() == "y";
                        }
                        else
                        {
                            v = value == null ? null : value;
                        }

                        var variable = prop.SetMethod;

                        if (!r.IsNull(displayName))
                        {
                            variable.Invoke(medicalFacility, new object[] { v });
                        }
                    }
                }
                medicalFacilities.Add(medicalFacility);
            }
        }
        return(medicalFacilities);
    }
    protected void SubmitMedicalFacility(object sender, EventArgs e)
    {
        try
        {
            var medicalFacility = new MedicalFacilityModel();

            medicalFacility.City        = int.Parse(city.Value);
            medicalFacility.Address     = address.Value;
            medicalFacility.Email       = email.Value;
            medicalFacility.IsActive    = true;
            medicalFacility.Mobile      = mobile.Value;
            medicalFacility.Name        = name.Value;
            medicalFacility.Created     = DateTime.UtcNow.AddHours(5).AddMinutes(30);
            medicalFacility.Description = description.Value;

            if (hrs24.Checked)
            {
                medicalFacility.Timing = "24 hrs";
            }
            else
            {
                medicalFacility.Timing = timingFrom.Value + " to " + timingTo.Value;
            }

            var doctors    = new List <string>();
            var doctorKeys = Request.Form.AllKeys.Where(x => x.Contains("doctor")).ToList();
            foreach (var key in doctorKeys)
            {
                var i          = key.Replace("doctor", "");
                var docname    = Request.Form["doctor" + i];
                var degree     = Request.Form["degree" + i];
                var from       = Request.Form["timingFrom" + i];
                var to         = Request.Form["timingTo" + i];
                var docmobile  = Request.Form["docmobile" + i];
                var docservice = Request.Form["docservice" + i];

                var doc = "{" + string.Format("\"docname\":\"{0}\", \"degree\":\"{1}\",\"docmobile\":\"{2}\", \"docservice\":\"{3}\", \"timing\":\"{4} - {5}\"", docname, degree, docmobile, docservice, from, to) + "}";
                doctors.Add(doc);
            }
            medicalFacility.Doctor = "[" + string.Join(",", doctors) + "]";

            if (Request.Files.Count > 0)
            {
                var files = new List <string>();
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile f = Request.Files[i];
                    if (f.ContentLength > 0)
                    {
                        var extension = Path.GetExtension(f.FileName);
                        var fileName  = Guid.NewGuid().ToString() + "." + extension;
                        files.Add(fileName);

                        string pathToSave_100 = HttpContext.Current.Server.MapPath("~/photo/" + fileName);
                        f.SaveAs(pathToSave_100);
                    }
                }
                if (files.Count > 0)
                {
                    medicalFacility.Images = string.Join(" ", files);
                }
            }

            var servicesKeys = Request.Form.AllKeys.Where(x => x.Contains("clinicservice")).ToList();
            var services     = new List <string>();
            foreach (var key in servicesKeys)
            {
                var i = key.Replace("clinicservice", "");
                services.Add(Request.Form["clinicservice" + i]);
            }
            medicalFacility.Services = string.Join("\n", services);

            var sqlQuery = new Helper().GetInsertQuery <MedicalFacilityModel>(medicalFacility);
            if (!string.IsNullOrWhiteSpace(facility_id.Value))
            {
                medicalFacility.Id = int.Parse(facility_id.Value);
                sqlQuery           = new Helper().GetUpdateQuery <MedicalFacilityModel>(medicalFacility);
            }

            var dam = new DataAccessManager().ExecuteInsertUpdateQuery(sqlQuery);
            if (dam)
            {
                Response.Redirect("MedicalFacility", true);
            }
        }
        catch (Exception ex)
        {
            action.Value = "Failed To Add Medical Facility!";
        }
    }