Exemplo n.º 1
0
 public ActionResult _FatherAdd(int id)
 {
     // Load Male Animals
     ViewData["MaleParents"] = commonRep.GetMaleAnimalsDropDown(id);
     AnimalRelationship ins = new AnimalRelationship(id);
     return PartialView(ins);
 }
Exemplo n.º 2
0
        public AnimalRelationship InsertAnimalRelationship(AnimalRelationship ins)
        {
            AnimalRelationship ReturnObject = new AnimalRelationship();
            int ModifiedBy = (int)HttpContext.Current.Session["UserNo"];

            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection      con    = dbConn.SqlConn();

            con.Open();

            SqlCommand     cmdI = con.CreateCommand();
            SqlTransaction trx  = con.BeginTransaction(CommonStrings.InsertTransaction);

            cmdI.Connection  = con;
            cmdI.Transaction = trx;

            try
            {
                cmdI.Parameters.Clear();
                cmdI.CommandText = CommonStrings.InsertAnimalRelationship;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@ParentId", ins.ParentAnimalId);
                cmdI.Parameters.AddWithValue("@ChildId", ins.ChildAnimalId);
                cmdI.Parameters.AddWithValue("@ModifiedDate", DateTime.Now);
                cmdI.Parameters.AddWithValue("@ModifiedBy", ModifiedBy);
                cmdI.Parameters.AddWithValue("@Removed", false);

                ins.RelationshipId = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null)
                {
                    trx.Rollback();
                }
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }

                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }

            return(ins);
        }
Exemplo n.º 3
0
        public JsonResult _InsertBirthHistory(BirthHistory ins)
        {
            ins = aiRep.InsertBirthHistory(ins);

            if((ins.HistoryId != 0) && (ins.ChildId != 0))
            {
                AnimalRelationship father = new AnimalRelationship();
                father.ParentAnimalId = ins.MaleParentId;
                father.ChildAnimalId = ins.ChildId;
                father = animalRep.InsertAnimalRelationship(father);

                AnimalRelationship mother = new AnimalRelationship();
                mother.ParentAnimalId = ins.FemaleParentId;
                mother.ChildAnimalId = ins.ChildId;
                mother = animalRep.InsertAnimalRelationship(mother);
            }

            return Json(new GridModel(commonRep.GetBirthHistories()));
        }
Exemplo n.º 4
0
        public AnimalRelationship InsertAnimalRelationshipSim(AnimalRelationship ins)
        {
            AnimalRelationship ReturnObject = new AnimalRelationship();

            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();

            SqlCommand cmdI = con.CreateCommand();
            SqlTransaction trx = con.BeginTransaction(CommonStrings.InsertTransaction);

            cmdI.Connection = con;
            cmdI.Transaction = trx;

            try
            {
                cmdI.Parameters.Clear();
                cmdI.CommandText = CommonStrings.InsertAnimalRelationship;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@ParentId", ins.ParentAnimalId);
                cmdI.Parameters.AddWithValue("@ChildId", ins.ChildAnimalId);
                cmdI.Parameters.AddWithValue("@ModifiedDate", ins.ModiefiedDate);
                cmdI.Parameters.AddWithValue("@ModifiedBy", ins.ModifiedBy);
                cmdI.Parameters.AddWithValue("@Removed", false);

                ins.RelationshipId = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null) trx.Rollback();
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }

                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }

            return ins;
        }
Exemplo n.º 5
0
        public ActionResult _AddParent(AnimalRelationship ins)
        {
            ins = animalRep.InsertAnimalRelationship(ins);

            return RedirectToAction("Tag", new { id = ins.ChildAnimalId });
        }
Exemplo n.º 6
0
        public JsonResult AddBirthScenario(int FemaleId, int MaleId, int ChildId, int TubeId, int BirthTypeId, int Success, int CompanyId, int UserKey, DateTime ModifiedDate)
        {
            //...Check if Tube was used
            if(TubeId != 0)
            {
                //...Tube was used, save history record
                InseminationHistory insem = new InseminationHistory();
                insem.AnimalId = FemaleId;
                insem.TubeId = TubeId;
                insem.CompanyId = CompanyId;
                insem.ModifiedBy = UserKey;
                insem.ModifiedDate = ModifiedDate.AddDays(-274);

                insem = aiRep.InsertInseminationHistorySim(insem);

                if(insem.HistoryId == 0)
                {
                    return Json(insem.HistoryId, JsonRequestBehavior.AllowGet);
                }
            }

            //...Insert Birth History
            BirthHistory birth = new BirthHistory();
            birth.BirthTypeId = BirthTypeId;
            birth.ChildId = ChildId;
            birth.CompanyId = CompanyId;
            birth.FemaleParentId = FemaleId;
            birth.MaleParentId = MaleId;
            birth.ModifiedBy = UserKey;
            birth.Success = (Success == 1) ? true : false;
            birth.TubeId = TubeId;
            birth.ModifiedDate = ModifiedDate;

            birth = aiRep.InsertBirthHistorySim(birth);

            if ((birth.HistoryId != 0) && (birth.ChildId != 0))
            {
                AnimalRelationship father = new AnimalRelationship();
                father.ParentAnimalId = birth.MaleParentId;
                father.ChildAnimalId = birth.ChildId;
                father.ModiefiedDate = ModifiedDate;
                father.ModifiedBy = UserKey;
                father = aniRep.InsertAnimalRelationshipSim(father);

                AnimalRelationship mother = new AnimalRelationship();
                mother.ParentAnimalId = birth.FemaleParentId;
                mother.ChildAnimalId = birth.ChildId;
                mother.ModiefiedDate = ModifiedDate;
                mother.ModifiedBy = UserKey;
                mother = aniRep.InsertAnimalRelationshipSim(mother);
            }

            return Json(birth.HistoryId, JsonRequestBehavior.AllowGet);
        }