예제 #1
0
        public Result <WorkerInfo> Save(WorkerInfo userinfo)
        {
            var result = new Result <WorkerInfo>();

            try
            {
                var objtosave = DbContext.WorkerInfos.FirstOrDefault(u => u.UserId == userinfo.UserId);
                if (objtosave == null)
                {
                    objtosave = new WorkerInfo();
                    DbContext.WorkerInfos.Add(objtosave);
                }
                objtosave.EarnedMoney = userinfo.EarnedMoney;
                objtosave.RatePerHour = userinfo.RatePerHour;



                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
예제 #2
0
        private WorkerInfo ConvertToEntity(DataRow row)
        {
            try
            {
                WorkerInfo u = new WorkerInfo();
                u.UserId      = Int32.Parse(row["UserID"].ToString());
                u.EarnedMoney = Int32.Parse(row["EarnedMoney"].ToString());
                u.RatePerHour = row["RatePerHour"].ToString();



                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #3
0
        private bool IsValid(WorkerInfo obj, Result <WorkerInfo> result)
        {
            if (!ValidationHelper.IsStringValid(obj.EarnedMoney.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid EarnedMoney";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.RatePerHour))
            {
                result.HasError = true;
                result.Message  = "Invalid RatePerHour";
                return(false);
            }


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

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

                if (dt == null || dt.Rows.Count == 0)
                {
                    WorkerInfo.UserId = CurrentUser.User.UserId;
                    query             = "insert into WorkerInfo values(" + WorkerInfo.UserId + ",'" + WorkerInfo.EarnedMoney + "','" + WorkerInfo.RatePerHour + "')";
                }
                else
                {
                    query = "update WorkerInfo set EarnedMoney=" + WorkerInfo.EarnedMoney + ",RatePerHour='" + WorkerInfo.RatePerHour + "' where UserId=" +
                            WorkerInfo.UserId;
                }



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

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = WorkerInfo;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
예제 #5
0
        public List <WorkerInfo> GetAll()
        {
            var result = new List <WorkerInfo>();

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

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