Exemplo n.º 1
0
        public Result <PostAProject> Save(PostAProject PostAProject)
        {
            var result = new Result <PostAProject>();

            try
            {
                var objtosave = DbContext.PostAProjects.FirstOrDefault(u => u.PostId == PostAProject.PostId);
                if (objtosave == null)
                {
                    objtosave = new PostAProject();
                    DbContext.PostAProjects.Add(objtosave);
                }
                objtosave.WUserId     = PostAProject.WUserId;
                objtosave.ProjectName = PostAProject.ProjectName;
                objtosave.Price       = PostAProject.Price;
                objtosave.StartTime   = PostAProject.StartTime;
                objtosave.EndTime     = PostAProject.EndTime;
                objtosave.Description = PostAProject.Description;
                objtosave.Members     = PostAProject.Members;



                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        private bool IsValid(PostAProject obj, Result <PostAProject> result)
        {
            if (!ValidationHelper.IsStringValid(obj.ProjectName))
            {
                result.HasError = true;
                result.Message  = "Invalid School Name";
                return(false);
            }



            return(true);
        }
Exemplo n.º 3
0
        private bool IsValid(PostAProject obj, Result <PostAProject> result)
        {
            if (!ValidationHelper.IsStringValid(obj.WUserId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid WUserId";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.ProjectName))
            {
                result.HasError = true;
                result.Message  = "Invalid ProjectName";
                return(false);
            }

            if (!ValidationHelper.IsStringValid(obj.Price.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid Price";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.StartTime.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid StartTime";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.EndTime.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid EndTime";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Description))
            {
                result.HasError = true;
                result.Message  = "Invalid Description";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Members.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid Members";
                return(false);
            }


            return(true);
        }
Exemplo n.º 4
0
 private bool IsValidToSave(PostAProject obj, Result <PostAProject> result)
 {
     if (!ValidationHelper.IsIntValid(obj.PostId.ToString()))
     {
         result.HasError = true;
         result.Message  = "Invalid UserID";
         return(false);
     }
     if (DbContext.PostAProjects.Any(u => u.PostId == obj.PostId))
     {
         result.HasError = true;
         result.Message  = "Email PostId";
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
        public Result <PostAProject> Save(PostAProject PostAProject)
        {
            var result = new Result <PostAProject>();

            try
            {
                string query = "select * from PostAProject where PostID=" + PostAProject.PostId;
                var    dt    = DataAccess.GetDataTable(query);

                if (dt == null || dt.Rows.Count == 0)
                {
                    PostAProject.PostId = GetID();
                    var d = PostAProject.StartTime.ToString(string.Format("dd/MMM/yyyy"));
                    var b = PostAProject.EndTime.ToString(string.Format("dd/MMM/yyyy"));
                    query = "insert into PostAProject values(" + PostAProject.PostId + "," + 1 + ",'" + PostAProject.ProjectName + "'," + PostAProject.Price + ",'" + d + "','" + b + "','" + PostAProject.Description + "'," + PostAProject.Members + ")";
                }
                else
                {
                    query = "update PostAProject set ProjectName='" + PostAProject.ProjectName + "',StartTime='" + PostAProject.StartTime + "',EndTime='" + PostAProject.EndTime + "',Description='" + PostAProject.Description + "',Price=" + PostAProject.Price + ",Members=" + PostAProject.Members + " where PostID=" + PostAProject.PostId;
                }

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

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

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = PostAProject;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Exemplo n.º 6
0
        public List <PostAProject> GetAll()
        {
            var result = new List <PostAProject>();

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

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i <= dt.Rows.Count; i++)
                    {
                        PostAProject u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Exemplo n.º 7
0
        private PostAProject ConvertToEntity(DataRow row)
        {
            try
            {
                PostAProject u = new PostAProject();
                u.PostId  = Int32.Parse(row["PostID"].ToString());
                u.WUserId = Int32.Parse(row["WUserID"].ToString());
                u.Price   = Int32.Parse(row["Price"].ToString());
                u.Members = Int32.Parse(row["Members"].ToString());

                u.ProjectName = row["ProjectName"].ToString();

                u.Description = row["Description"].ToString();
                u.StartTime   = Convert.ToDateTime(row["StartTime"]);
                u.EndTime     = Convert.ToDateTime(row["EndTime"]);


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