Пример #1
0
        public TEUnit_Onboarding AddUnit_Onboarding(TEUnit_Onboarding value)
        {
            try
            {
                TEUnit_Onboarding result = value;

                if (!(value.Uniqueid + "".Length > 0))
                {
                    //Create
                    result.CreatedOn      = System.DateTime.Now;
                    result.LastModifiedOn = System.DateTime.Now;
                    result = db.TEUnit_Onboarding.Add(value);
                }
                else
                {
                    //Edit
                    db = new TEHRIS_DevEntities();
                    db.TEUnit_Onboarding.Attach(value);
                    foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties())
                    {
                        string propname = item.Name;
                        if (propname.ToLower() == "createdon")
                        {
                            continue;
                        }
                        object propValue = item.GetValue(value);
                        if (propValue != null || Convert.ToString(propValue).Length != 0)
                        {
                            db.Entry(value).Property(propname).IsModified = true;
                        }
                    }

                    value.LastModifiedOn = System.DateTime.Now;
                    db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true;
                }
            }
            catch (Exception ex)
            {
                db.ApplicationErrorLogs.Add(
                    new ApplicationErrorLog
                {
                    Error             = ex.Message,
                    ExceptionDateTime = System.DateTime.Now,
                    InnerException    = ex.InnerException != null ? ex.InnerException.Message : "",
                    Source            = "From TEUnitonboard| AddUnit_Onboarding | " + this.GetType().ToString(),
                    Stacktrace        = ex.StackTrace
                }
                    );
            }

            db.SaveChanges();
            return(db.TEUnit_Onboarding.Find(value.Uniqueid));
        }
        public object SendContact(TEUnit_Onboarding value)
        {
            TEUnit_Onboarding unit     = db.TEUnit_Onboarding.Where(x => x.Uniqueid == value.Uniqueid).ToList().First();
            UserProfile       userinfo = db.UserProfiles.Where(x => x.UserId == unit.UserID).ToList().First();

            if (userinfo != null)
            {
                int?tower = 0;
                try
                {
                    TEProjects_UNIT projectunit = db.TEProjects_UNIT.Where(x => (x.PROJECT_ID == value.Project) &&
                                                                           (x.AREA == value.Unit)).ToList().First();
                    if (projectunit != null)
                    {
                        tower = projectunit.TOWERID;
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
                TEContact contact = new TEContact
                {
                    ApprovedBy = userinfo.CallName,
                    ApprovedOn = System.DateTime.Now,
                    CreatedBy  = userinfo.CallName,
                    CreatedOn  = System.DateTime.Now,
                    //Have to be dynamic...

                    IsDeleted               = false,
                    LastModifiedBy          = userinfo.CallName,
                    LastModifiedOn          = System.DateTime.UtcNow,
                    Projectid               = value.Project,
                    Towerid                 = tower,
                    Unitid                  = value.Unit,
                    Mobile                  = userinfo.Phone,
                    Emailid                 = userinfo.email,
                    DOB                     = System.DateTime.Now,
                    DOM                     = System.DateTime.Now,
                    Type                    = "",
                    PrefferedContact        = "",
                    PrefferedMode           = "",
                    ISProfileSPublic        = false,
                    IsAdvertise             = false,
                    Photo                   = userinfo.photo,
                    Salutation              = "",
                    FirstName               = "",
                    MiddleName              = "",
                    LastName                = "",
                    CallName                = userinfo.CallName,
                    ContactType             = "",
                    Nationality             = "",
                    CountryOfBirth          = "",
                    Age                     = 0,
                    Gender                  = "",
                    MaritalStatus           = "",
                    Category                = "",
                    Importance              = "",
                    PrefferedSaleConsultant = "",
                    TEOrganisation          = 0,
                    Status                  = value.Status,
                    //Type
                };
                return(db.TEContacts.Add(contact));
            }
            return("Success");
        }
        public TEUnit_Onboarding AddTEUnitOnboarding(TEUnit_Onboarding value)
        {
            TEUnit_Onboarding result = value;



            if (!(value.Uniqueid + "".Length > 0))
            {
                //Create
                result.CreatedOn      = System.DateTime.Now;
                result.LastModifiedOn = System.DateTime.Now;
                result = db.TEUnit_Onboarding.Add(value);
            }
            else
            {
                //Edit
                db = new TEHRIS_DevEntities();
                db.TEUnit_Onboarding.Attach(value);
                foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties())
                {
                    string propname = item.Name;
                    if (propname.ToLower() == "createdon")
                    {
                        continue;
                    }
                    object propValue = item.GetValue(value);
                    if (propValue != null || Convert.ToString(propValue).Length != 0)
                    {
                        db.Entry(value).Property(propname).IsModified = true;
                    }
                }

                value.LastModifiedOn = System.DateTime.Now;
                db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true;

                if (value.Status == "Active")
                {
                    db.Configuration.ProxyCreationEnabled = false;
                    TEUnit_Onboarding unit = db.TEUnit_Onboarding.Where(x => x.Uniqueid == value.Uniqueid).ToList().First();
                    if (unit != null)
                    {
                        string email = (from teuser in db.UserProfiles
                                        where (teuser.UserId == unit.UserID)
                                        select teuser.email).ToList().First();
                        //string tecontact = (from teoint in db.TEContacts
                        //                    where ((teoint.Emailid == email) && (teoint.Projectid == value.Project) && (teoint.Unitid == value.Unit))
                        //                    select teoint.CallName).ToList().First();
                        //if (tecontact == null)
                        try
                        {
                            TEContact contact = db.TEContacts.Where(x => (x.Emailid == email) &&
                                                                    (x.Projectid == value.Project) &&
                                                                    (x.Unitid == value.Unit)).ToList().First();
                            if (contact != null)
                            {
                                SendContact(value);
                            }
                        }
                        catch (Exception ex)
                        { SendContact(value);
                          ex.Message.ToString(); }
                    }
                }
            }

            db.SaveChanges();

            //CRUD Mobile
            //CRUD Email
            //CRUD Address

            return(db.TEUnit_Onboarding.Find(value.Uniqueid));
        }