public ActionResult MessageSent(int value)
 {
     //var getOwner = new DataheirAddHandler().FindIdOwner(Current.UserId);
     var userFather = new DataheirAddHandler().FindFatherInfo(value);
     var sent = new DataheirAddHandler();
     sent.SendDeadReport(value, userFather);
     return RedirectToAction("Message", "Recipient");
 }
        public ActionResult Signin4(MessageModel form)
        {
            User usersData = null ;
            DataheirCreateModel dataheirData = null;
            List<DataheirCreateModel> witnessData = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //storing information about new user
                    UsersAddHandler usersAddHandler1 = new UsersAddHandler();
                    usersData = (User)Session["Signin1Store"];
                    User user = usersAddHandler1.Find(usersData.Email);
                    //UserCreateHandler userCreateHandler = new UserCreateHandler();

                    //var user = Core.User.CreateOwner(usersData.FirstName, usersData.LastName, usersData.UserName, usersData.Password, usersData.Email, usersData.CountryId, 0, 0, null, 0, System.DateTime.Now, 1, 0, false, false, true, false, false);
                    //UsersAddHandler.Save(user);
                    //userCreateHandler.Handle(user);

                    ////Add path for new photo
                    //var path = "~/Swisskip/" + user.UserName;
                    //if (!System.IO.Directory.Exists(Server.MapPath(path)))
                    //    System.IO.Directory.CreateDirectory(Server.MapPath(path));

                    //Session["path"] = path;
                    ////Session["username"] = user.UserName;

                    ////Creating a default photo
                    //string newFile = Server.MapPath("~/Content/images/") + user.UserName + ".jpg";
                    //if (!System.IO.File.Exists(newFile))
                    //    System.IO.File.Copy(Server.MapPath("~/Content/images/unknown.jpg"), Server.MapPath("~/Content/images/") + user.UserName + ".jpg");

                    //AuthenticationService.SignIn(user);

                    ////Link new owner with Trial Mode - Status=1 : new owner
                    //var user_userType1 = User_UserType.CreateRelationUserAndUserType(0, user.Id, (int)UserRoles.Owner, 0, System.DateTime.Now, 0, 0, 1);
                    //UsersAddHandler.Save(user_userType1);

                    dataheirData = (DataheirCreateModel)Session["Signin2Store"];
                    DataheirAddHandler dataheirAddHandler = new DataheirAddHandler();

                    //Validating Dataheir's Email already existed
                    UsersAddHandler usersAddHandler = new UsersAddHandler();
                    User ExistedUser = usersAddHandler.Find(dataheirData.Email);
                    User dataheir = new User();

                    //Find info already existed in DB
                    if (ExistedUser != null && ExistedUser.Email == dataheirData.Email)
                    {
                        ExistedUser.IsDataheir = true;
                        usersAddHandler.Update(ExistedUser);
                        dataheir = ExistedUser;
                        ExistedUser = null;
                    }
                    else
                    {
                        dataheir = Core.User.CreateDataheir(dataheirData.FirstName, dataheirData.LastName, dataheirData.UserName, dataheirData.Password, dataheirData.Email, null, null, dataheirData.CountryId, null, 0, 0, null, 0, System.DateTime.Now, 0, 0, null, false, false, false, true, false);
                        UsersAddHandler.Save(dataheir);
                    }

                    //Sent Confirmation
                    dataheirAddHandler.Handle(user, dataheir, form.DataheirMsg);

                    //Link new owner with Trial Mode
                    var user_userType2 = User_UserType.CreateRelationUserAndUserType(user.Id, dataheir.Id, (int)UserRoles.Dataheir, 0, System.DateTime.Now, 0, 0, 0);
                    UsersAddHandler.Save(user_userType2);

                    //Create Witness
                    witnessData = (List<DataheirCreateModel>)Session["Signin3Store"];
                    WitnessesAddHandler witnessAddHandler = new WitnessesAddHandler();
                    User witness = new User();

                    for (int i = 0; i < witnessData.Count; i++)
                    {
                        //Adding validations - new!
                        User ExistedUser1 = usersAddHandler.Find(witnessData[i].Email);

                        if (ExistedUser1 != null && ExistedUser1.Email == witnessData[i].Email)
                        {
                            ExistedUser1.IsWitness = true;
                            usersAddHandler.Update(ExistedUser1);
                            witness = ExistedUser1;
                        }
                        else
                        {
                            witness = Core.User.CreateWitness(witnessData[i].FirstName, witnessData[i].LastName, witnessData[i].UserName, witnessData[i].Password, witnessData[i].Email, null, null, witnessData[i].CountryId, null, 0, 0, null, 0, System.DateTime.Now, 0, 0, null, false, false, false, false, true);
                            UsersAddHandler.Save(witness);
                        }

                        //Sent Confirmation
                        witnessAddHandler.Handle(user, witness, form.WitnessMsg);

                        //Link new owner with Trial Mode
                        var user_userType3 = User_UserType.CreateRelationUserAndUserType(user.Id, witness.Id, (int)UserRoles.Witness, 0, System.DateTime.Now, 0, 0, 0);
                        UsersAddHandler.Save(user_userType3);
                        witness = null;
                        ExistedUser1 = null;
                    }

                }
                catch (ValidationException e)
                {
                    ModelState.AddModelError(e.Key, e.Message);
                    return this.View();
                }
            }

            //if (!ModelState.IsValid)
            //    return this.View();

            //if (invitationId.HasValue)
            //{
            //User user1 = Current.Connection.Get<User>(Current.UserId);
            //AuthenticationService.SignIn(user1);
            //    return new RedirectToAccountType(user);
            //}

            Session["Signin1Store"] = usersData;
            Session["Signin2Store"] = dataheirData;
            Session["Signin3Store"] = witnessData;
            return RedirectToAction("Signin5", "Registration");
        }