Esempio n. 1
0
        public ActionResult DefineSlPurchOrg(tblOrganizationStructure obj)
        {
            IStructuredetailRepository objstruct = new StructuredetailRepository();

            var validate = objstruct.Getcondition1(obj.CompanyCode, Convert.ToInt32(obj.CityCode)).FirstOrDefault();

            var validate1 = objstruct.Getvalidation(obj.CompanyCode, Convert.ToInt32(obj.CityCode), obj.StorageLocation, obj.PurchaseOrganization).FirstOrDefault();

            var validate2 = context.tblOrganizationStructures
                            .Where(a => a.CompanyCode == obj.CompanyCode)
                            .Where(b => b.CityCode == obj.CityCode).FirstOrDefault();
            var validate3 = context.tblOrganizationStructures
                            .Where(c => c.StorageLocation == obj.StorageLocation)
                            .Where(d => d.PurchaseOrganization == obj.PurchaseOrganization).FirstOrDefault();

            if (validate == null)
            {
                TempData["ErrorMessage"] = ("CompanyCode " + obj.CompanyCode + " with CityCode " + obj.CityCode + " Does not Exists");
            }

            else if (validate2 != null && validate3 != null)
            {
                TempData["ErrorMessage"] = (" Storage Location " + obj.StorageLocation + " with Purchase Organization " + obj.PurchaseOrganization + "Already Exists for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + " ");
            }
            else if (validate != null && validate1 == null && validate3 == null && validate2 != null)
            {
                if (ModelState.IsValid)
                {
                    List <object> lst = new List <object>();
                    lst.Add(obj.CompanyCode);
                    lst.Add(obj.CityCode);
                    lst.Add(obj.StorageLocation);
                    lst.Add(obj.PurchaseOrganization);
                    object[] item    = lst.ToArray();
                    int      output1 = context.Database.ExecuteSqlCommand("insert into tblOrganizationStructure(CompanyCode,CityCode,StorageLocation,PurchaseOrganization) values(@p0,@p1,@p2,@p3)", item);
                    if (output1 > 0)
                    {
                        TempData["SuccessMessage"] = ("Storage Location " + obj.StorageLocation + " and Purchase Org " + obj.PurchaseOrganization + " Defined for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + "");
                    }
                }
                else
                {
                    TempData["ErrorMessage"] = "Unable to Add";
                }
            }
            else if (validate2 == null && validate3 != null || validate2 == null && validate3 == null)
            {
                if (ModelState.IsValid)
                {
                    List <object> lst = new List <object>();
                    lst.Add(obj.CompanyCode);
                    lst.Add(obj.CityCode);
                    lst.Add(obj.StorageLocation);
                    lst.Add(obj.PurchaseOrganization);
                    object[] item    = lst.ToArray();
                    int      output1 = context.Database.ExecuteSqlCommand("insert into tblOrganizationStructure(CompanyCode,CityCode,StorageLocation,PurchaseOrganization) values(@p0,@p1,@p2,@p3)", item);
                    if (output1 > 0)
                    {
                        TempData["SuccessMessage"] = ("Storage Location " + obj.StorageLocation + " and Purchase Org " + obj.PurchaseOrganization + " Defined for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + "");
                    }
                }
                else
                {
                    TempData["ErrorMessage"] = "Unable to Add";
                }
            }
            else
            {
                TempData["ErrorMessage"] = (" Storage Location " + obj.StorageLocation + " with Purchase Organization " + obj.PurchaseOrganization + "Already Exists for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + " ");
            }
            return(View(obj));
        }