public ActionResult CreateSubProject([Bind(Include = "Id,Name,Description,StartDate,EndDate,City,Location,Category")] Project project)
        {
            if (ModelState.IsValid)
            {
                Project mainproject = db.Projects.Find(project.Id);
                if (mainproject != null)
                {
                    mainproject.TotalSubProjects++;
                    if (mainproject.SubProjectIds != null)
                    {
                        if (mainproject.SubProjectIds.Length > 0) {
                            mainproject.SubProjectIds = string.Concat(mainproject.SubProjectIds, ",");
                        }
                        mainproject.SubProjectIds = string.Concat(mainproject.SubProjectIds, project.Name);
                    }
                    else
                    {
                        mainproject.SubProjectIds = project.Name;
                    }
                    db.Entry(mainproject).State = EntityState.Modified;
                }

                Project subProject = new Project();
                subProject.StartDate = project.StartDate;
                subProject.EndDate = project.EndDate;
                subProject.City = project.City;
                subProject.Location = project.Location;

                subProject.Name = project.Name;
                subProject.Description = project.Description;
                subProject.Category = project.Category;

                subProject.CreatedOn = DateTime.Now;
                subProject.ModifiedOn = DateTime.Now;
                subProject.TotalSpentAmount = 0;
                subProject.ParentProjectId = project.Id;
                subProject.TotalSubProjects = 0;
                subProject.TotalAllocatedAmount = 0;
                subProject.IsParent = false;
                subProject.SubProjectIds = "";

                db.Projects.Add(subProject);

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(project);
        }
        public ActionResult CreateSubProject([Bind(Include = "Id,Name,Description,StartDate,EndDate,City,Location,Category")] Project project, string amount)
        {
            if (ModelState.IsValid)
            {
                Double allocatedAmount = 0;
                Project mainproject = db.Projects.Find(project.Id);
                if (mainproject != null)
                {
                    var remaining = mainproject.TotalAllocatedAmount - mainproject.TotalSpentAmount;
                    if((amount != null) && (amount.Length > 0))
                    {
                        if (!amount.All(char.IsDigit))
                        {
                            ViewBag.AvailableAmount = mainproject.TotalAllocatedAmount - mainproject.TotalSpentAmount;
                            ViewBag.message = "Allocated Amount should be valid number";
                            return View(project);
                        }
                        allocatedAmount = Convert.ToDouble(amount);
                    }
                    if (remaining < allocatedAmount)
                    {
                        ViewBag.AvailableAmount = mainproject.TotalAllocatedAmount - mainproject.TotalSpentAmount;
                        ViewBag.message = "Allocated Amount can not be more than Available Amount";
                        return View(project);
                    }
                    mainproject.TotalSubProjects++;
                    mainproject.TotalSpentAmount = mainproject.TotalSpentAmount + allocatedAmount;
                    if (mainproject.SubProjectIds != null)
                    {
                        if (mainproject.SubProjectIds.Length > 0) {
                            mainproject.SubProjectIds = string.Concat(mainproject.SubProjectIds, ",");
                        }
                        mainproject.SubProjectIds = string.Concat(mainproject.SubProjectIds, project.Name);
                    }
                    else
                    {
                        mainproject.SubProjectIds = project.Name;
                    }
                    db.Entry(mainproject).State = EntityState.Modified;
                }

                Project subProject = new Project();
                subProject.StartDate = project.StartDate;
                subProject.EndDate = project.EndDate;
                subProject.City = project.City;
                subProject.Location = project.Location;

                subProject.Name = project.Name;
                subProject.Description = project.Description;
                subProject.Category = project.Category;

                subProject.CreatedOn = DateTime.Now;
                subProject.ModifiedOn = DateTime.Now;
                subProject.TotalSpentAmount = 0;
                subProject.ParentProjectId = project.Id;
                subProject.TotalSubProjects = 0;
                subProject.TotalAllocatedAmount = allocatedAmount;
                subProject.IsParent = false;
                subProject.SubProjectIds = "";

                db.Projects.Add(subProject);

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(project);
        }