Example #1
0
        private List <WorkingCC> ReadWorkingCondition()
        {
            List <WorkingCC> conditions = new List <WorkingCC>();

            path = Path.Combine(basepath, @"Data\WorkingCondition.txt");

            using (StreamReader reader = new StreamReader(path))
            {
                using (TextFieldParser parser = new TextFieldParser(reader))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters("\t");
                    while (!parser.EndOfData)
                    {
                        string[] fields    = parser.ReadFields();
                        var      condition = new WorkingCC();
                        condition.Id             = Guid.NewGuid();
                        condition.CostCenterCode = fields[0].Trim();
                        condition.Condition      = (ConditionType)Enum.Parse(typeof(ConditionType), fields[1].Trim());
                        condition.CCAStart       = fields[2].Trim();
                        condition.NewCreateTimeStamp("Seed");
                        conditions.Add(condition);
                    }
                }
            }
            return(conditions);
        }
        public ActionResult AddWorkingCC(WorkingCC working)
        {
            try
            {
                if (!working.IsValid())
                {
                    throw new Exception("กรุณาระบุข้อมูลให้ครบถ้วน");
                }
                using (var db = new BudgetContext())
                {
                    working.Id = Guid.NewGuid();
                    working.NewCreateTimeStamp();
                    db.WorkingCCs.Add(working);
                    db.SaveChanges();
                    returnobj.SetSuccess(working);
                }
            }
            catch (Exception ex)
            {
                returnobj.SetError(ex.Message);
            }

            return(Content(returnobj.ToJson(), "application/json"));
        }