Пример #1
0
        private bool IsValid(ProjectSection obj, Result <ProjectSection> result)
        {
            if (!ValidationHelper.IsStringValid(obj.PostId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid PostId";
                return(false);
            }


            if (!ValidationHelper.IsStringValid(obj.SectionName))
            {
                result.HasError = true;
                result.Message  = "Invalid SectionName";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Percentage.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid Percentage";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Price.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid Price";
                return(false);
            }

            return(true);
        }
Пример #2
0
        public Result <ProjectSection> Save(ProjectSection userinfo)
        {
            var result = new Result <ProjectSection>();

            try
            {
                var objtosave = DbContext.ProjectSections.FirstOrDefault(u => u.ProjectSectionId == userinfo.ProjectSectionId);
                if (objtosave == null)
                {
                    objtosave = new ProjectSection();
                    DbContext.ProjectSections.Add(objtosave);
                }
                objtosave.PostId      = userinfo.PostId;
                objtosave.SectionName = userinfo.SectionName;
                objtosave.Percentage  = userinfo.Percentage;
                objtosave.Price       = userinfo.Price;


                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Пример #3
0
        private bool IsValid(ProjectSection obj, Result <ProjectSection> result)
        {
            if (!ValidationHelper.IsStringValid(obj.SectionName))
            {
                result.HasError = true;
                result.Message  = "Invalid School Name";
                return(false);
            }



            return(true);
        }
Пример #4
0
        public Result <ProjectSection> Save(ProjectSection ProjectSection)
        {
            var result = new Result <ProjectSection>();

            try
            {
                string query = "select * from ProjectSection where ProjectSectionId=" + ProjectSection.ProjectSectionId;
                var    dt    = DataAccess.GetDataTable(query);

                if (dt == null || dt.Rows.Count == 0)
                {
                    ProjectSection.ProjectSectionId = GetID();
                    ProjectSection.PostId           = GetID2();
                    query = "insert into ProjectSection values(" + ProjectSection.ProjectSectionId + "," + ProjectSection.PostId + ",'" + ProjectSection.SectionName + "','" + ProjectSection.Percentage + "'," + ProjectSection.Price + ")";
                }
                else
                {
                    query = "update ProjectSection set SectionName='" + ProjectSection.SectionName + "',Percentage='" + ProjectSection.Percentage + "',Price=" + ProjectSection.Price + " where PostID=" + ProjectSection.PostId;
                }

                if (!IsValid(ProjectSection, result))
                {
                    return(result);
                }

                result.HasError = DataAccess.ExecuteQuery(query) <= 0;

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = ProjectSection;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Пример #5
0
        private ProjectSection ConvertToEntity(DataRow row)
        {
            try
            {
                ProjectSection u = new ProjectSection();
                u.PostId = Int32.Parse(row["PostID"].ToString());

                u.Price       = Int32.Parse(row["Price"].ToString());
                u.Percentage  = Int32.Parse(row["Percentage"].ToString());
                u.SectionName = row["SectionName"].ToString();



                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #6
0
        public List <ProjectSection> GetAll()
        {
            var result = new List <ProjectSection>();

            try
            {
                string query = "select * from ProjectSection";
                var    dt    = DataAccess.GetDataTable(query);

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i <= dt.Rows.Count; i++)
                    {
                        ProjectSection u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Пример #7
0
        private ProjectSection ConvertToEntity(DataRow row)
        {
            try
            {
                ProjectSection u = new ProjectSection();
                u.PostId           = Int32.Parse(row["PostID"].ToString());
                u.ProjectSectionId = Int32.Parse(row["PROJECTSECTIONID"].ToString());

                u.Price              = Int32.Parse(row["Price"].ToString());
                u.Percentage         = Int32.Parse(row["Percentage"].ToString());
                u.SectionName        = row["SectionName"].ToString();
                u.SectionDescription = row["SECTIONDESCRIPTION"].ToString();
                u.FinishTime         = row["FINISHTIME"].ToString();
                u.WorkerName         = row["WORKERNAME"].ToString();



                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }