예제 #1
0
        private bool IsValid(OwnerInfo obj, Result <OwnerInfo> result)
        {
            if (!ValidationHelper.IsStringValid(obj.CompanyName))
            {
                result.HasError = true;
                result.Message  = "Invalid CompanyName";
                return(false);
            }


            if (!ValidationHelper.IsStringValid(obj.CompanyAddress))
            {
                result.HasError = true;
                result.Message  = "Invalid CompanyAddress";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.CompanyCode))
            {
                result.HasError = true;
                result.Message  = "Invalid CompanyCode";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.Position))
            {
                result.HasError = true;
                result.Message  = "Invalid Position";
                return(false);
            }

            return(true);
        }
예제 #2
0
        public Result <OwnerInfo> Save(OwnerInfo userinfo)
        {
            var result = new Result <OwnerInfo>();

            try
            {
                var objtosave = DbContext.OwnerInfos.FirstOrDefault(u => u.UserId == userinfo.UserId);
                if (objtosave == null)
                {
                    objtosave = new OwnerInfo();
                    DbContext.OwnerInfos.Add(objtosave);
                }
                objtosave.CompanyName    = userinfo.CompanyName;
                objtosave.CompanyAddress = userinfo.CompanyAddress;
                objtosave.CompanyCode    = userinfo.CompanyCode;

                objtosave.Position = userinfo.Position;


                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
예제 #3
0
        private OwnerInfo ConvertToEntity(DataRow row)
        {
            try
            {
                OwnerInfo u = new OwnerInfo();
                u.UserId         = Int32.Parse(row["UserId"].ToString());
                u.CompanyName    = row["CompanyName"].ToString();
                u.CompanyAddress = row["CompanyAddress"].ToString();
                u.CompanyCode    = row["CompanyCode"].ToString();
                u.Position       = row["Position"].ToString();


                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #4
0
        public Result <OwnerInfo> Save(OwnerInfo OwnerInfo)
        {
            var result = new Result <OwnerInfo>();

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

                if (dt == null || dt.Rows.Count == 0)
                {
                    // OwnerInfo.UserId = GetID();
                    query = "insert into OwnerInfo values(" + OwnerInfo.UserId + ",'" + OwnerInfo.CompanyName + "','" + OwnerInfo.CompanyAddress + "','" + OwnerInfo.CompanyCode + "','" + OwnerInfo.Position + "')";
                }
                else
                {
                    query = "update OwnerInfo set CompanyName='" + OwnerInfo.CompanyName + "',CompanyCode='" + OwnerInfo.CompanyCode + "',CompanyAddress='" + OwnerInfo.CompanyAddress + "',Position='" + OwnerInfo.Position + "' where UserId=" +
                            OwnerInfo.UserId;
                }

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

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

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = OwnerInfo;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
예제 #5
0
        //private int GetID()
        //{
        //    string query = "select * from OwnerInfo order by UserId desc";
        //    var dt = DataAccess.GetDataTable(query);
        //    int id = 1;

        //    if (dt != null && dt.Rows.Count != 0)
        //        id = Int32.Parse(dt.Rows[0]["ID"].ToString()) + 1;

        //    return id;
        //}
        public List <OwnerInfo> GetAll()
        {
            var result = new List <OwnerInfo>();

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

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i <= dt.Rows.Count; i++)
                    {
                        OwnerInfo u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }