Esempio n. 1
0
        public ActionResult Edit(ViewModelAC4 aC4)
        {
            try
            {
                var oldAc4 = _db.AccAC4.SingleOrDefault(b => b.Id == aC4.Id);
                if (oldAc4 != null)
                {
                    oldAc4.AC4Name = aC4.AC4Name;
                    oldAc4.AC3Id   = aC4.AC3Id;

                    oldAc4.AC2Id = aC4.AC2Id;
                    oldAc4.AC1Id = aC4.AC1Id;

                    if (ModelState.IsValid)
                    {
                        _db.Entry(oldAc4).State = EntityState.Modified;
                        _db.SaveChanges();
                    }
                }



                return(JavaScript(string.Format("UYResult('{0}','{1}','{2}','{3}')", "Data saved successfully.", "success", "redirect", Url.Content("~/Accounting/AC4/Index"))));
            }
            catch (Exception ex)
            {
                return(JavaScript(string.Format("UYResult('{0}','{1}')", ex.Message, "failure")));
            }
        }
Esempio n. 2
0
        public JavaScriptResult Create(ViewModelAC4 vmaC4)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var userId = Convert.ToInt32(Session["UserID"]);

                    //Convert viewmodel to entity
                    var ac4 = vmaC4.MakeAc4(userId);


                    if (vmaC4.IsAccountLedger)
                    {
                        var isNameAvailble5 = _db.AccACDetails.Any(x => x.ACName == vmaC4.AC4Name);
                        if (isNameAvailble5)
                        {
                            return(JavaScript(string.Format("UYResult('{0}','{1}')", "Same Name already exists in Level 5!", "failure")));
                        }

                        var vmAc5 = new ViewModelAC5
                        {
                            AC1Id  = ac4.AC1Id,
                            AC2Id  = ac4.AC2Id,
                            AC3Id  = ac4.AC3Id,
                            AC4Id  = ac4.Id,
                            ACName = ac4.AC4Name
                        };
                        var aC5 = vmAc5.MakeAc5(userId);

                        _db.AccACDetails.Add(aC5);
                    }

                    _db.AccAC4.Add(ac4);
                    _db.SaveChanges();


                    return(JavaScript(string.Format("UYResult('{0}','{1}','{2}','{3}')", "Data saved successfully.", "success",
                                                    "redirect", Url.Content("~/Accounting/AC4/Create"))));
                }

                return(JavaScript(string.Format("UYResult('{0}','{1}')", "Please provide valid data", "failure")));
            }


            catch (Exception ex)
            {
                return(JavaScript(string.Format("UYResult('{0}','{1}')", ex.Message, "failure")));
            }
        }