/// <summary>
        /// Edit division details.
        /// </summary>
        /// <param name="Id">Division Id</param>
        /// <returns> Divisiondetails</returns>
        public ActionResult DivisionEdit(int id)
        {
            MODEL.Division division = null;
            try
            {
                DivisionService divisionService = new DivisionService();

                //Get division details
                DivisionVO divisionVO = divisionService.GetDivisionById(id);
                if (divisionVO == null)
                {
                    ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.DIVISION));
                }
                else
                {
                    division = new Division(divisionVO);
                    division.defaultInvoiceInAdvancedList = GetInvoiceInAdvancedList();
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(PartialView("DivisionDetails", division));
        }
 /// <summary>
 /// Create a new division for the specified company
 /// </summary>
 /// <returns></returns>
 public ActionResult DivisionCreate(int companyId, string companyName)
 {
     try
     {
         MODEL.Division division = new MODEL.Division();
         division.CompanyId   = companyId;
         division.CompanyName = companyName;
         division.defaultInvoiceInAdvancedList = GetInvoiceInAdvancedList();
         division.IsActive = true;
         return(PartialView("DivisionDetails", division));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeAndErrorResult(500, e.Message));
     }
 }
        /// <summary>
        /// Save the Division details.
        /// </summary>
        /// <param name="model">The division model</param>
        /// <returns></returns>
        public ActionResult DivisionSave(MODEL.Division model)
        {
            try
            {
                DivisionService       divisionService = new DivisionService();
                List <MODEL.Division> Division        = new List <MODEL.Division>();

                if (ModelState.IsValid)
                {
                    //Get user id
                    int?userId = Session.GetUserId();

                    //DivisionVO divisionVO = new DivisionVO(model, userId.Value);

                    DivisionVO divisionVO = model.Transpose(userId);

                    divisionService.SaveDivision(divisionVO);

                    List <DivisionVO> divisionVOlist = divisionService.GetDivisionListByCompany(model.CompanyId);

                    foreach (DivisionVO division in divisionVOlist)
                    {
                        Division.Add(new MODEL.Division(division));
                    }
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.DIVISION));
                }
            }
            catch (ApplicationException e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }