[RESOLVED]How to edit in MVC using the Class Libraray Function?..

Hi Friends,

                    My requirement is to Edit a record in Mvc4 .I have created the Class Library Fuctions for editing a record .I have given the code bellow 

through that help me out in clearly .I am new to mvc  Technologies .

DataLayerFunction:

public bool EditCricket(CrickeCommontEntity Cricket, int PlayerId)
{

using (CRICKETEntities Context = new CRICKETEntities())
{

var Temp = Context.PLARYERHISTORies.Where(m => m.PLAYER_ID == PlayerId).SingleOrDefault();

if(Temp!=null)
{
Cricket.Common_Player_Id = Temp.PLAYER_ID;
Cricket.Common_Player_Name = Temp.PLAYER_NAME;
Cricket.Common_Country = Temp.COUNTRY;
Cricket.Common_Player_Role = Temp.PLAYER_ROLE;
Cricket.Common_Play_For = Temp.PLAY_FOR;
Cricket.Common_Total_Runs = Temp.TOTAL_RUNS;
Cricket.Common_Total_Wickets = Temp.TOTAL_WICKETS;
Cricket.Common_Catches = Temp.CATCHES;
Cricket.Common_Player_Rank = Temp.PLAYER_RANK;

};
Context.SaveChanges();
return true;

}

}

BusinessLayer Function:

public bool EditCricketBl(CrickeCommontEntity Cricket, int PlayerId)
{
ICricketDataLayer ObjDB = new CricketDataLayer();
bool Status = false;
Status= ObjDB.EditCricket(Cricket, PlayerId);

return Status;
}

HomeController Finction:

[HttpPost]
public ActionResult Edit(int id, CrickeCommontEntity Crik)
{
ICricketInteraction ObjDB = new CricketInteraction();
try
{
// TODO: Add update logic here

if (ModelState.IsValid)
{

}
else
{
return View();
}

return RedirectToAction("Index");
}
catch
{
return View();
}
}

                     Here , I would like to know the how to call that Edit Function.  Provide me with example Code .

Thanks in Advance ,

Karthik K

 

 

Give the request

Karthik Che

I would like to know the how to call that Edit Function.  Provide me with example Code .

you are not 

Karthik Che

new to mvc  Technologies .

but to programming per se.

As answer: You will create am instance of the class that have 

Karthik Che

public bool EditCricketBl(CrickeCommontEntity Cricket, int PlayerId)

and call it.

If you do not understand , please follow tutorials about C# – you can start here: http://www.asp.net/mvc

@ignatandrei,

          I did not understand what you train to say. I could say one thing .I May have flaws in my sanity . But i am so inters tested to Correct those flaws .

  If Possible help me out ,otherwise no issue . 

Thanks ,

 

 

Karthik Che

I would like to know the how to call that Edit Function

You can call the your Edit function by the way of form post. You should typically have another edit function which contains the html form and elements. Please take a look at this example

http://www.codeproject.com/Articles/695850/Complete-CRUD-Operations-in-MVC

Karthik Che

[HttpPost]
public ActionResult Edit(int id, CrickeCommontEntity Crik)
{
ICricketInteraction ObjDB = new CricketInteraction();
try
{
// TODO: Add update logic here

if (ModelState.IsValid)
{

}
else
{
return View();
}

return RedirectToAction("Index");
}
catch
{
return View();
}
}

may be like this,

 [HttpPost]
        public ActionResult Edit(int id, CrickeCommontEntity Crik)
        {
           // ICricketInteraction ObjDB = new CricketInteraction(); is this the business layer class?
            bool status;
            try
            {
                if (ModelState.IsValid)
                {

                    status = BusinessLayerClass.EditCricketBl(Crik, id);
                    if (!status)
                    {
                        ModelState.AddModelError("", "Error updating record, contact administrator");
                        return View();
                    }
                    else
                        return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }
            }
            catch
            {
                ModelState.AddModelError("", "Error updating record, contact administrator");
                return View();
            }
        }

Leave a Reply