コード例 #1
0
        public async Task <ActionResult> CreateBloodBank([FromBody] BloodBankModel bloodBank)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiResponse {
                    Status = false, ModelState = ModelState
                }));
            }

            var instance = BloodBank.Create(bloodBank.Doctor);

            try
            {
                var newBloodBank = await _repository.AddAsync(instance);

                if (newBloodBank == null)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(CreatedAtRoute("GetBloodBankRoute", new { id = newBloodBank.BloodBankId },
                                      new ApiResponse {
                    Status = true, BloodBank = newBloodBank
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
コード例 #2
0
        public async Task <ActionResult> UpdateBloodBank(Guid id, [FromBody] BloodBankModel bloodBank)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiResponse {
                    Status = false, ModelState = ModelState
                }));
            }

            var instance = await _repository.GetByIdAsync(id);

            try
            {
                instance.Update(bloodBank.Type, bloodBank.Doctor);

                var status = await _repository.UpdateAsync(instance);

                if (!status)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(Ok(new ApiResponse {
                    Status = true, BloodBank = instance
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
コード例 #3
0
    public PagedList <BloodBankModel> GetAllBloodBanksPaginated(int skip, int take, string order, string where)
    {
        var bloodBanks = new List <BloodBankModel>();
        var orderBy    = string.IsNullOrEmpty(order) ? " order by bm.created_on desc " : order;
        var query      = "select bm.*, cm.city_name from blood_bank_master bm, city_master cm where bm.city_id = cm.city_id and  bm.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 bloodBank = new BloodBankModel();
                var props     = typeof(BloodBankModel).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(bloodBank, new object[] { v });
                        }
                    }
                }
                bloodBanks.Add(bloodBank);
            }
        }
        query = "select count(*) from blood_bank_master bm, city_master cm where bm.city_id = cm.city_id and  bm.is_active='y' " + where;
        var totalCount = new DataAccessManager().ExecuteScalar(query);
        var count      = totalCount != null?int.Parse(totalCount.ToString()) : 0;

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

        return(result);
    }
コード例 #4
0
    public List <BloodBankModel> GetAllBloodBank()
    {
        var bloodBanks = new List <BloodBankModel>();
        var query      = "select * from blood_bank_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 bloodBank = new BloodBankModel();
                var props     = typeof(BloodBankModel).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(bloodBank, new object[] { v });
                        }
                    }
                }
                bloodBanks.Add(bloodBank);
            }
        }
        return(bloodBanks);
    }
コード例 #5
0
    protected void SubmitBloodBank(object sender, EventArgs e)
    {
        try
        {
            var bloodBank = new BloodBankModel();

            bloodBank.City    = int.Parse(city.Value);
            bloodBank.Email   = email.Value;
            bloodBank.Mobile  = mobile.Value;
            bloodBank.Address = address.Value;

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

            bloodBank.OpeningYear = opening_year.Value;

            bloodBank.Name     = blood_bank_name.Value;
            bloodBank.IsActive = true;
            bloodBank.Created  = DateTime.UtcNow.AddHours(5).AddMinutes(30);

            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)
                {
                    bloodBank.Images = string.Join(" ", files);
                }
            }

            var sqlQuery = new Helper().GetInsertQuery <BloodBankModel>(bloodBank);
            if (!string.IsNullOrWhiteSpace(blood_bank_id.Value))
            {
                bloodBank.Id = int.Parse(blood_bank_id.Value);
                sqlQuery     = new Helper().GetUpdateQuery <BloodBankModel>(bloodBank);
            }

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