public ActionResult Create(Levi_EntryModel levi_entryModel)
        {
            var end_date = "9999-12-31";
            Levi_Entry levi_entry = new Levi_Entry();
            if (ModelState.IsValid)
            {
                var is_exist = (from le in db.Levi_Entry where le.levi_name == levi_entryModel.levi_name && le.end_date == end_date select le).Count();
                if (is_exist > 0)
                {
                    TempData["errorMessage"] = "This Levy Name Already Exist";
                }
                else
                {
                    levi_entry.levi_name = levi_entryModel.levi_name;
                    levi_entry.description = levi_entryModel.description;
                    levi_entry.levi_type_id = levi_entryModel.levi_type_id;
                    if (levi_entryModel.goods_category_id == 0)
                    {
                        levi_entry.goods_heirarchy_id = 0;
                        levi_entry.goods_item = null;
                    }
                    else if (levi_entryModel.goods_subcategory_id == 0)
                    {
                        levi_entry.goods_heirarchy_id = 1;
                        levi_entry.goods_item = levi_entryModel.goods_category_id;
                    }
                    else if (levi_entryModel.goods_type_id == 0)
                    {
                        levi_entry.goods_heirarchy_id = 2;
                        levi_entry.goods_item = levi_entryModel.goods_subcategory_id;
                    }
                    else if (levi_entryModel.goods_item == 0)
                    {
                        levi_entry.goods_heirarchy_id = 3;
                        levi_entry.goods_item = levi_entryModel.goods_type_id;
                    }
                    else
                    {
                        levi_entry.goods_heirarchy_id = 4;
                        levi_entry.goods_item = levi_entryModel.goods_item;
                    }
                    levi_entry.ispercentage = levi_entryModel.ispercentage;
                    levi_entry.levi = levi_entryModel.levi;
                    levi_entry.status_id = 1;
                    levi_entry.start_date = Convert.ToDateTime(DateTime.Now.ToString()).ToString("yyyy-MM-dd");
                    levi_entry.end_date = "9999-12-31";
                    levi_entry.isprocessed = false;
                    db.Levi_Entry.Add(levi_entry);
                    db.SaveChanges();
                    db.Update_Levi();
                    TempData["errorMessage"] = "Levy Added Successfully";
                }
                return RedirectToAction("Index");
            }

            return RedirectToAction("Index");
        }
        public ActionResult Create(Levi_EntryModel levi_entryModel)
        {
            if (Session["login_status"] != null)
            {
                int[] z = (int[])Session["function_id"];
                var is_perentage_no = 0;
                if (z.Contains(16))
                {
                    var file_name = "";
                    var end_date = "9999-12-31";
                    var date_end = Convert.ToDateTime("9999-12-31");
                    Levi_Entry levi_entry = new Levi_Entry();
                    if (ModelState.IsValid)
                    {
                        var is_exist = (from le in db.Levi_Entry where le.levi_name == levi_entryModel.levi_name && le.end_date == end_date select le).Count();
                        if (is_exist > 0)
                        {
                            TempData["errorMessage"] = "This Levy Name Already Exist";
                        }
                        else
                        {
                            if (levi_entryModel.upload_document != null)
                            {
                                //following code is used for document adding and storing in App_Data folder
                                HttpPostedFileBase file = Request.Files.Get("upload_document");

                                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                                {
                                    file_name = file.FileName;
                                    string fileContentType = file.ContentType;
                                    byte[] fileBytes = new byte[file.ContentLength];
                                    file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                                    var FileLocation = Path.Combine(Server.MapPath("~/App_Data"), file_name);
                                    file.SaveAs(FileLocation);
                                }
                            }
                            levi_entry.levi_name = levi_entryModel.levi_name;
                            levi_entry.description = levi_entryModel.description;
                            levi_entry.levi_type_id = levi_entryModel.levi_type_id;
                            if (levi_entryModel.goods_category_id == 0)
                            {
                                levi_entry.goods_heirarchy_id = 0;
                                levi_entry.goods_item = null;
                                if (levi_entryModel.ispercentage == false)
                                {
                                    TempData["errorMessage"] = "You can't add levy at flat rate here, there are multiple unit of measures";
                                    return RedirectToAction("Index");
                                }
                            }
                            else if (levi_entryModel.goods_subcategory_id == 0)
                            {
                                is_perentage_no = (from gt in db.Goods_Tariff
                                                   join g in db.Goods on gt.goods_id equals g.goods_id
                                                   join gtp in db.Goods_Type on g.goods_type_id equals gtp.goods_type_id
                                                   join gs in db.Goods_Subcategory on gtp.goods_subcategory_id equals gs.goods_subcategory_id
                                                   join gc in db.Goods_Category on gs.goods_category_id equals gc.goods_category_id
                                                   where gc.goods_category_id == levi_entryModel.goods_category_id && gt.end_date == date_end
                                                   select gt.unit_of_measure_id).Distinct().Count();
                                if (is_perentage_no > 1 && levi_entryModel.ispercentage == false)
                                {
                                    TempData["errorMessage"] = "You can't add levy at flat rate here, there are multiple unit of measures";
                                    return RedirectToAction("Index");
                                }
                                levi_entry.goods_heirarchy_id = 1;
                                levi_entry.goods_item = levi_entryModel.goods_category_id;
                            }
                            else if (levi_entryModel.goods_type_id == 0)
                            {
                                is_perentage_no = (from gt in db.Goods_Tariff
                                                   join g in db.Goods on gt.goods_id equals g.goods_id
                                                   join gtp in db.Goods_Type on g.goods_type_id equals gtp.goods_type_id
                                                   join gs in db.Goods_Subcategory on gtp.goods_subcategory_id equals gs.goods_subcategory_id
                                                   where gs.goods_subcategory_id == levi_entryModel.goods_subcategory_id && gt.end_date == date_end
                                                   select gt.unit_of_measure_id).Distinct().Count();
                                if (is_perentage_no > 1 && levi_entryModel.ispercentage == false)
                                {
                                    TempData["errorMessage"] = "You can't add levy at flat rate here, there are multiple unit of measures";
                                    return RedirectToAction("Index");
                                }
                                levi_entry.goods_heirarchy_id = 2;
                                levi_entry.goods_item = levi_entryModel.goods_subcategory_id;
                            }
                            else if (levi_entryModel.goods_item == 0)
                            {
                                is_perentage_no = (from gt in db.Goods_Tariff
                                                   join g in db.Goods on gt.goods_id equals g.goods_id
                                                   join gtp in db.Goods_Type on g.goods_type_id equals gtp.goods_type_id
                                                   where gtp.goods_type_id == levi_entryModel.goods_type_id && gt.end_date == date_end
                                                   select gt.unit_of_measure_id).Distinct().Count();
                                if (is_perentage_no > 1 && levi_entryModel.ispercentage == false)
                                {
                                    TempData["errorMessage"] = "You can't add levy at flat rate here, there are multiple unit of measures";
                                    return RedirectToAction("Index");
                                }
                                levi_entry.goods_heirarchy_id = 3;
                                levi_entry.goods_item = levi_entryModel.goods_type_id;
                            }
                            else
                            {
                                levi_entry.goods_heirarchy_id = 4;
                                levi_entry.goods_item = levi_entryModel.goods_item;
                            }
                            levi_entry.ispercentage = levi_entryModel.ispercentage;
                            levi_entry.is_on_subtotal = Convert.ToInt32(levi_entryModel.is_on_subtotal);
                            levi_entry.levi = levi_entryModel.levi;
                            levi_entry.currency_id = levi_entryModel.currency_id;
                            levi_entry.status_id = 1;
                            levi_entry.start_date = Convert.ToDateTime(DateTime.Now.ToString()).ToString("yyyy-MM-dd");
                            levi_entry.end_date = "9999-12-31";
                            levi_entry.isprocessed = false;
                            levi_entry.document_name = file_name;
                            db.Levi_Entry.Add(levi_entry);
                            db.SaveChanges();
                            db.Update_Levi();
                            TempData["errorMessage"] = "Levy Added Successfully";
                        }
                        return RedirectToAction("Index");
                    }

                    return RedirectToAction("Index");
                }
                else
                {
                    return RedirectToAction("../Home/Dashboard");
                }
            }
            else
            {
                return RedirectToAction("../Home");
            }
        }
 public ActionResult DbSearchresult(Levi_Entry levi_entry)
 {
     if (Session["login_status"] != null)
     {
         int[] z = (int[])Session["function_id"];
         if (z.Contains(16))
         {
             var end_date = "9999-12-31";
             if (levi_entry.levi_name != null)
             {
                 var result = from l in db.Levi_Entry
                              where l.levi_name == levi_entry.levi_name && l.end_date == end_date
                              select l.Levi_entry_id;
                 if (result.Count() > 0)
                 {
                     return RedirectToAction("Index", new { levi_entry_id = result.First() });
                 }
                 else
                 {
                     return RedirectToAction("Index", new { levi_entry_id = -1 });
                 }
             }
             return RedirectToAction("Index");
         }
         else
         {
             return RedirectToAction("../Home/Dashboard");
         }
     }
     else
     {
         return RedirectToAction("../Home");
     }
 }
 public ActionResult DbSearchresult(Levi_Entry levi_entry)
 {
     if (levi_entry.levi_name != null)
     {
         var result = from l in db.Levi_Entry
                      where l.levi_name == levi_entry.levi_name
                      select l.Levi_entry_id;
         if (result.Count() > 0)
         {
             return RedirectToAction("Index", new { levi_entry_id = result.First() });
         }
         else
         {
             return RedirectToAction("Index", new { levi_entry_id = -1 });
         }
     }
     return RedirectToAction("Index");
 }