Пример #1
0
        public ActionResult PayAll(FormCollection formCollection)
        {
            try
            {
                string[] ids  = formCollection["EmployeeId"].Split(new char[] { ',' });
                string[] ids2 = formCollection["Amount"].Split(new char[] { ',' });
                foreach (string id in ids)
                {
                    var     i       = Int32.Parse(id);
                    var     clients = _employeeservice.GetById(i);
                    CostLog costLog = new CostLog();
                    costLog.CostName     = "Salary";
                    costLog.EmployeeName = clients.Data.EmployeeName;
                    if (ids2[0].Equals(""))
                    {
                        if (clients.Data.Due != 0)
                        {
                            costLog.Amount   = clients.Data.Due;
                            clients.Data.Due = 0;
                        }
                        else
                        {
                            costLog.Amount = clients.Data.Salary;
                        }
                    }

                    else
                    {
                        costLog.Amount   = double.Parse(formCollection["Amount"]);
                        clients.Data.Due = clients.Data.Due - double.Parse(formCollection["Amount"]);
                    }


                    _costservice.Save(costLog);
                    _employeeservice.DueSet(clients.Data);
                    if (clients.HasError)
                    {
                        ViewBag.Message = clients.Message;
                        return(Content("Problem is : " + clients.Message));
                    }
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("CostList", "CostInfo", new { id = 1 }));
            }
            return(RedirectToAction("CostList", "CostInfo"));
        }
Пример #2
0
        public ActionResult CreateCost(CostLog costLog)
        {
            try
            {
                var result = _costservice.Save(costLog);
                if (result.HasError)
                {
                    ViewBag.Message = result.Message;
                    return(Content("Problem is : " + result.Message));
                }

                return(RedirectToAction("CostList"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Пример #3
0
        public Result <CostLog> Save(CostLog CostLog)
        {
            var result = new Result <CostLog>();

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

                if (dt == null || dt.Rows.Count == 0)
                {
                    CostLog.CostId = GetId();
                    var costDate = DateTime.Now.ToString(string.Format("dd/MMM/yyyy"));

                    query = "insert into CostLog values(" + CostLog.CostId + ",'" + CostLog.CostName.ToUpper() + "','" + costDate + "','" + CostLog.EmployeeName + "','" + CostLog.IssuedBy + "'," + CostLog.Amount + ")";
                }
                else
                {
                    query = "update CostLog set CostName='" + CostLog.CostName.ToUpper() + "', IssuedBy='" + CostLog.IssuedBy + "', EmployeeName='" + CostLog.EmployeeName + "', Amount=" + CostLog.Amount + " where CostId=" + CostLog.CostId;
                }

                //if (!IsValid(CostLog, result))
                //{
                //    return result;
                //}

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

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = CostLog;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Пример #4
0
        private CostLog ConvertToEntity(DataRow row)
        {
            try
            {
                CostLog u = new CostLog();
                u.CostId       = Int32.Parse(row["CostId"].ToString());
                u.Amount       = Int32.Parse(row["Amount"].ToString());
                u.CostName     = row["CostName"].ToString().Substring(0, 1).ToUpper() + row["CostName"].ToString().Substring(1).ToLower();
                u.EmployeeName = row["EmployeeName"].ToString();
                u.IssuedBy     = row["IssuedBy"].ToString();
                u.CostDate     = Convert.ToDateTime(row["CostDate"]);

                return(u);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #5
0
        public bool IsValid(CostLog obj, Result <CostLog> result)
        {
            if (!ValidationHelper.IsStringValid(obj.CostName))
            {
                result.HasError = true;
                result.Message  = "InvalUserId Cost Name";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.IssuedBy))
            {
                result.HasError = true;
                result.Message  = "InvalUserId IssuedBy Name";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.EmployeeName))
            {
                result.HasError = true;
                result.Message  = "InvalUserId Employee Name";
                return(false);
            }


            return(true);
        }