Beispiel #1
0
        public object GetAuthorityList(string textSearch, int currPage, int recordperpage)
        {
            // GetOrg
            string          orgCode = User.Claims.Where(u => u.Type == AuthorityConstant.orgCode).FirstOrDefault().Value;
            TblOrganization org     = new TblOrganization();

            if (!string.IsNullOrEmpty(orgCode))
            {
                org = _authorityRepository.GetOrganization(orgCode);
            }
            // GetUserId
            int userId = Int32.Parse(User.Claims.Where(u => u.Type == AccountConstant.userId).FirstOrDefault().Value);

            if (!string.IsNullOrEmpty(textSearch))
            {
                textSearch = textSearch.TrimEnd().TrimStart();
            }

            string arr = textSearch + AccountConstant.StringSlipSearch
                         + currPage + AccountConstant.StringSlipSearch
                         + recordperpage + AccountConstant.StringSlipSearch
                         + userId + AccountConstant.StringSlipSearch
                         + org.OrganizationId
            ;

            return(Json(_authorityRepository.GetAuthorityList(arr)));
        }
Beispiel #2
0
        // [Test]
        public void TestAddUser()
        {
            int save = 0;
            UserAndOrgViewModel model = new UserAndOrgViewModel();

            TblOrganization org = new TblOrganization()
            {
                OrganizationId         = 2,
                OrganizationCode       = "MP",
                OrganizationParentCode = null,
                OrganizationName       = "CT TNHH Minh Phúc",
                OrganizationAddress    = "Mễ Trì, Nam Từ Liêm",
                OrganizationEmail      = "*****@*****.**",
                OrganizationPhone      = null,
                OrganizationTaxCode    = null,
                OrganizationRemark     = null,
                OrganizationFrom       = null,
                CreateBy             = null,
                CreateDate           = null,
                UpdateBy             = null,
                UpdateDate           = Convert.ToDateTime("2019-03-03 00:00:00.000"),
                IsActive             = false,
                IsLock               = null,
                IsDelete             = false,
                OrganizationTo       = null,
                OrganizationHomePage = null
            };

            // Add model
            model.tblUsers        = GetUser(1);
            model.tblOrganization = org;

            Assert.AreEqual(save, 1);
        }
Beispiel #3
0
        //[Test]
        public void TestEditUser()
        {
            UserAndOrgViewModel model = new UserAndOrgViewModel();

            TblUsers user = new TblUsers
            {
                //Id =
                UserName           = "******",
                Password           = "******",
                FullName           = "Hoang Manh Hai",
                Email              = "*****@*****.**",
                PhoneNumber        = "1234567890",
                CreateBy           = "Admin",
                CreateDate         = Convert.ToDateTime("2018-12-26T11 =53 =47.327"),
                UpdateBy           = "",
                UpdateDate         = Convert.ToDateTime("2019-03-29T11 =53 =00.263"),
                IsDelete           = false,
                IsLock             = false,
                Avatar             = null,
                Address            = null,
                LastLogin          = null,
                Position           = null,
                EmailConfirmed     = true,
                Gender             = 1,
                LoginFail          = 0,
                HistoryPassword    = "******",
                DateUpdatePassword = Convert.ToDateTime("2019-04-01T00 =00 =00")
            };

            TblOrganization org = new TblOrganization()
            {
                OrganizationId         = 2,
                OrganizationCode       = "MP",
                OrganizationParentCode = null,
                OrganizationName       = "CT TNHH Minh Phúc",
                OrganizationAddress    = "Mễ Trì, Nam Từ Liêm",
                OrganizationEmail      = "*****@*****.**",
                OrganizationPhone      = null,
                OrganizationTaxCode    = null,
                OrganizationRemark     = null,
                OrganizationFrom       = null,
                CreateBy             = null,
                CreateDate           = null,
                UpdateBy             = null,
                UpdateDate           = Convert.ToDateTime("2019-03-03 00:00:00.000"),
                IsActive             = false,
                IsLock               = null,
                IsDelete             = false,
                OrganizationTo       = null,
                OrganizationHomePage = null
            };

            // Add model
            model.tblUsers        = user;
            model.tblOrganization = org;

            //Assert.AreEqual(save, _ac.Compare(2, 1));
        }
Beispiel #4
0
        public IActionResult UpdateAuthority([FromBody] AuthorityRoleViewModel model)
        {
            ErrorObject     response = new ErrorObject();
            ResponseMessage rm       = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (model.tblAuthority == null)
            {
                rm.Type    = AuthorityConstant.TypeAuthority;
                rm.Title   = AuthorityConstant.TitleAddAuthority;
                rm.Message = AuthorityConstant.MessageAddAuthority;
                rm.Status  = AuthorityConstant.statusError;
                var field = new { fieldErrors = rm.Title };

                return(StatusCode(400, Json(rm)));
            }
            else
            {
                string          orgCode = User.Claims.Where(u => u.Type == AuthorityConstant.orgCode).FirstOrDefault().Value;
                TblOrganization org     = _authorityRepository.GetOrganization(orgCode);
                if (org != null)
                {
                    model.tblAuthority.OrganizationId = org.OrganizationId;
                    if (String.IsNullOrEmpty(model.tblAuthority.OrganizationId.ToString()) || model.tblAuthority.OrganizationId == 0)
                    {
                        rm.Type    = AuthorityConstant.TypeAuthority;
                        rm.Title   = AuthorityConstant.TitleAddAuthorityNullOrg;
                        rm.Message = AuthorityConstant.MessageAddAuthorityNullOrg;
                        rm.Status  = AuthorityConstant.statusError;
                        var field = new { fieldErrors = rm.Title };

                        return(StatusCode(400, Json(rm)));
                    }
                    else
                    {
                        model.tblAuthority.UpdateBy = User.Claims.FirstOrDefault().Value;
                        TblAuthority au = _authorityRepository.UpdateAuthority(model);
                        if (au == null)
                        {
                            response.entityName = AuthorityConstant.TypeAuthority;
                            response.errorKey   = AuthorityConstant.ErrorKeyAddError;
                            response.status     = AuthorityConstant.statusError;
                            response.message    = AuthorityConstant.MessageAddError;
                            return(StatusCode(400, Json(response)));
                        }
                        return(StatusCode(200, Json(au)));
                    }
                }
                return(BadRequest());
            }
        }
Beispiel #5
0
 /// <summary>
 /// HaiHM
 /// Get TblOrganization By OrganizationCode
 /// </summary>
 /// <param name="orgCode"></param>
 /// <returns></returns>
 public TblOrganization GetOrganization(string orgCode)
 {
     try
     {
         TblOrganization org = db.TblOrganization.Where(o => String.Compare(o.OrganizationCode, orgCode, false) == 0).FirstOrDefault();
         return(org);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(null);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Function get organization by Code
 /// CreatedBy: HaiHM
 /// CreatedDate: 6/5/2019
 /// </summary>
 /// <param name="orgCode">filter</param>
 /// <returns>null or organization same filter</returns>
 public TblOrganization GetOrganization(string orgCode)
 {
     try
     {
         TblOrganization org = db.TblOrganization.Where(o => o.IsDelete == false && o.OrganizationCode == orgCode).FirstOrDefault();
         return(org);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw ex;
     }
 }
Beispiel #7
0
        /// <summary>
        /// Function get all infor ỏg
        /// CreatedBy: HaiHM
        /// CreatedDated: 25/5/2019
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <object> GetInforOrganization(int userId)
        {
            try
            {
                TblOrganization orgResult = new TblOrganization();

                var lstOrg = from a in db.TblOrganization
                             where (from c in db.TblOrganizationUser where c.UserId == userId select c.OrganizationId).Contains(a.OrganizationId)
                             select a;
                List <TblOrganization> lstauT = lstOrg.ToList();
                if (lstauT.Count() > 0)
                {
                    TblOrganization org = lstauT.FirstOrDefault();
                    if (org != null)
                    {
                        string str = OrganizationConstant.DirectoryUploads + org.OrganizationCode + OrganizationConstant.DirectorySlat + org.OrganizationCode + ".png";
                        if (File.Exists(_environment.WebRootPath + str))
                        {
                            org.OrganizationLogo = await ImageToBase64Async(str);
                        }
                        else
                        {
                            string defaultLogo = OrganizationConstant.DirectoryUploads + OrganizationConstant.LinkDefaulfLogo;
                            if (File.Exists(_environment.WebRootPath + defaultLogo))
                            {
                                org.OrganizationLogo = await ImageToBase64Async(defaultLogo);
                            }
                            else
                            {
                                org.OrganizationLogo = await ImageToBase64Async(OrganizationConstant.DirectoryUploads + OrganizationConstant.DirectorySlat + OrganizationConstant.LinkDefaulfLogo1);
                            }
                        }
                        orgResult = org;
                    }
                }

                var lstSP = from a in db.TblServicePack
                            where (from c in db.TblOrganizationServicePack where c.OrganizationId == orgResult.OrganizationId select c.ServicePackId).Contains(a.Id)
                            select a;
                List <TblServicePack> listServicePack = lstSP.ToList();

                var obj = new { Organization = orgResult, servicePack = listServicePack };

                return(obj);
            }
            catch (Exception ex)
            {
                var obj = new { code = 400, message = ex.Message };
                return(obj);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Function check duplicate name authority
        /// CreatedBy: HaiHM
        /// CreatedDate: 25/5/2019
        /// </summary>
        /// <param name="name"></param>
        /// <param name="orgCode"></param>
        /// <returns></returns>
        public bool CheckDuplicate(int id, string name, string orgCode)
        {
            bool result = false;

            try
            {
                TblOrganization org = GetOrganization(orgCode);
                if (!string.IsNullOrEmpty(id.ToString()) && !string.IsNullOrEmpty(name) && id != 0)
                {
                    TblAuthority aut = db.TblAuthority.Where(o => o.OrganizationId == org.OrganizationId && o.IsDelete == false && o.AuthorityId == id).FirstOrDefault();
                    if (aut != null)
                    {
                        if (name.Trim().ToLower() != aut.AuthorityName.Trim().ToLower())
                        {
                            if (db.TblAuthority.Where(o => o.OrganizationId == org.OrganizationId && o.IsDelete == false &&
                                                      o.AuthorityName.Trim().ToLower() == name.Trim().ToLower()).Count() > 0)
                            {
                                return(false);
                            }
                            else
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    if (name != aut.AuthorityName)
                    {
                        if (db.TblAuthority.Where(au => au.IsDelete == false && au.AuthorityName == name && au.OrganizationId == id).Count() > 0)
                        {
                            return(false);
                        }
                    }
                }
                TblAuthority authority = db.TblAuthority.Where(au => au.OrganizationId == org.OrganizationId && au.IsDelete == false && au.AuthorityName.TrimEnd().TrimStart().ToLower() == name.TrimEnd().TrimStart().ToLower()).FirstOrDefault();
                if (authority == null)
                {
                    return(true);
                }
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(true);
            }

            return(result);
        }
Beispiel #9
0
 public int UpdateOrganizationLogo(TblOrganization Organization)
 {
     try
     {
         db.Entry(Organization).State = EntityState.Modified;
         db.SaveChanges();
         return(1);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(0);
     }
 }
Beispiel #10
0
 public void UpdateLogoInforOrg(TblOrganization organization)
 {
     try {
         TblOrganization OrgSave = db.TblOrganization.Where(a => a.OrganizationId == organization.OrganizationId && a.IsDelete == false).FirstOrDefault();
         if (OrgSave != null)
         {
             OrgSave.OrganizationLogo = organization.OrganizationLogo;
             db.Entry(OrgSave).State  = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #11
0
        public static OrganizationObj MagicMapper(this TblOrganization item)
        {
            if (item == null)
            {
                return(null);
            }

            OrganizationObj obj = new OrganizationObj
            {
                OrganizationId = item.OrganizationId,
                SiteId         = item.SiteId,
                LabelE         = item.LabelE,
                AcronymE       = item.AcronymE,
                LabelF         = item.LabelF,
                AcronymF       = item.AcronymF,
                Active         = item.Active
            };

            return(obj);
        }
Beispiel #12
0
        /// <summary>
        ///  // Active Organization
        /// </summary>
        /// <param name="OrganizationId"></param>
        /// <param name="IsCheckedOrg"></param>
        /// <returns></returns>

        public int ActiveOrganization(int OrganizationId, bool IsCheckedOrg)
        {
            int result = 0;

            try
            {
                TblOrganization OrgChk = db.TblOrganization.Where(a => a.OrganizationId == OrganizationId).FirstOrDefault();
                if (OrgChk != null)
                {
                    OrgChk.IsActive        = IsCheckedOrg;
                    db.Entry(OrgChk).State = EntityState.Modified;
                    db.SaveChanges();
                    result = 1;
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                throw ex;
            }
        }
Beispiel #13
0
        public int UpdateInforOrganization(TblOrganization organization, int userId, string username)
        {
            int    updateOrg = OrganizationConstant.UpdateOrgFail;
            string email     = "";
            string taxCode   = "";
            string name      = "";

            try
            {
                TblOrganization org = db.TblOrganization.Where(o => o.OrganizationId == organization.OrganizationId && o.IsDelete == false).FirstOrDefault();  //GetOrganizationId(userId);
                if (organization != null)
                {
                    if (!string.IsNullOrEmpty(organization.OrganizationEmail))
                    {
                        email = organization.OrganizationEmail.Trim().ToLower();
                    }
                    if (!string.IsNullOrEmpty(organization.OrganizationTaxCode))
                    {
                        taxCode = organization.OrganizationTaxCode.Trim();
                    }
                    if (!string.IsNullOrEmpty(organization.OrganizationName))
                    {
                        name = organization.OrganizationName.Trim();
                    }
                    if (organization.OrganizationId == org.OrganizationId)
                    {
                        //Check Email
                        if (org.OrganizationEmail.ToLower() != email)
                        {
                            if (db.TblOrganization.Where(u => u.IsDelete == false &&
                                                         u.OrganizationEmail.Trim().ToLower() == email).Count() > 0)
                            {
                                // Duplicate Email
                                return(OrganizationConstant.UpdateOrgDuplicateEmail);
                            }
                        }
                        // Check OrganizationTaxCode
                        if (org.OrganizationTaxCode.Trim().ToLower() != taxCode)
                        {
                            if (db.TblOrganization.Where(u => u.IsDelete == false &&
                                                         organization.OrganizationTaxCode.Trim().ToLower() == u.OrganizationTaxCode.Trim().ToLower()).Count() > 0)
                            {
                                // Duplicate TaxCode
                                return(OrganizationConstant.UpdateOrgDuplicateTaxCode);
                            }
                        }
                        if (!string.IsNullOrEmpty(organization.OrganizationName))
                        {
                            org.OrganizationName = name;
                        }
                        if (!string.IsNullOrEmpty(organization.OrganizationEmail))
                        {
                            org.OrganizationEmail = organization.OrganizationEmail.Trim().ToLower();
                        }
                        org.OrganizationPhone = organization.OrganizationPhone.Trim();
                        if (!string.IsNullOrEmpty(organization.OrganizationTaxCode))
                        {
                            org.OrganizationTaxCode = organization.OrganizationTaxCode.Trim();
                        }
                        org.OrganizationAddress  = organization.OrganizationAddress;
                        org.OrganizationNote     = organization.OrganizationNote;
                        org.OrganizationRemark   = organization.OrganizationRemark;
                        org.OrganizationHomePage = organization.OrganizationHomePage;

                        org.OrganizationLogo = organization.OrganizationLogo;
                        org.UpdateBy         = username;
                        org.UpdateDate       = DateTime.Now;
                        db.Entry(org).State  = EntityState.Modified;
                        db.SaveChanges();
                        return(OrganizationConstant.UpdateOrgSuccess);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(updateOrg);
            }
            return(updateOrg);
        }
Beispiel #14
0
        public async Task <string> Get()
        {
            var DbContent = DB_config.db_conection();

            TblOrganization tblOrganizations = new TblOrganization();

            tblOrganizations.City = "Erunakulam";
            DbContent.TblOrganizations.Add(tblOrganizations);

            //upload Multiple files
            List <string> s = new List <string>();

            s.Add("E:\\a.txt");
            s.Add("E:\\b.txt");
            s.Add("E:\\ac.txt");

            FileOperations.upload(s);

            //How to call Download method.
            FileDownloadBase64String fileinfo = await FileOperations.Download("b.txt");

            // Call Log implementation method.
            //
            LogModel logModel = new LogModel();

            logModel.LogType = LogTypes.Error;
            logModel.Message = "Success";

            Log log = new Log();

            log.LogWrite(logModel);

            // Maill function

            GMailServices gMailServices = new GMailServices();

            gMailServices.SendMail("*****@*****.**", "Test", "Hello Ramabose");


            // insert and update samples


            //var org = new TblOrganization
            //{
            //    OrganizationName = "",
            //    OrganizationCode = "",
            //    OrganizationEmail = "",
            //    OrganizationAddress1 = "",
            //    OrganizationContact = "",
            //    OrganizationType = "",
            //    OrganizationAddress2 = "",
            //    City = "",
            //    State = "",
            //    PinCode = "",
            //    OrganizationLogo = "",
            //    DelFlag = true,
            //    CreatedDate = DateTime.Now,
            //    UpdatedDate = DateTime.Now,

            //};

            //DbContent.TblOrganizations.Add(org);
            //DbContent.SaveChanges();

            return("Good");
        }
Beispiel #15
0
        /// <summary>
        /// Sua Don Vi
        /// </summary>
        /// <param name="Org"></param>
        /// <returns></returns>
        public int UpdateOrganization(UpdateOrg model)
        {
            int result = 0;

            try
            {
                TblOrganization OrgChk = db.TblOrganization.Where(r => r.OrganizationId == model.Org.OrganizationId && r.IsDelete == false).FirstOrDefault();


                using (var ts = new TransactionScope())
                {
                    if (OrgChk != null)
                    {
                        if (OrgChk.OrganizationCode != model.Org.OrganizationCode)
                        {
                            if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationCode == model.Org.OrganizationCode).Count() > 0)
                            {
                                // Duplicate DuplicateOrgCode
                                return(result = 411);
                            }
                        }

                        if (OrgChk.OrganizationEmail != model.Org.OrganizationEmail)
                        {
                            if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationEmail == model.Org.OrganizationEmail).Count() > 0)
                            {
                                // Duplicate DuplicateEmail
                                return(result = 412);
                            }
                        }

                        if (OrgChk.OrganizationTaxCode != model.Org.OrganizationTaxCode)
                        {
                            if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationTaxCode == model.Org.OrganizationTaxCode).Count() > 0)
                            {
                                // Duplicate DuplicateOrgTaxCode
                                return(result = 413);
                            }
                        }


                        OrgChk.CreateBy               = model.Org.CreateBy;
                        OrgChk.IsDelete               = model.Org.IsDelete;
                        OrgChk.CreateDate             = model.Org.CreateDate;
                        OrgChk.IsActive               = model.Org.IsActive;
                        OrgChk.IsLock                 = model.Org.IsLock;
                        OrgChk.UpdateBy               = model.Org.UpdateBy;
                        OrgChk.UpdateDate             = DateTime.Now;
                        OrgChk.OrganizationAddress    = model.Org.OrganizationAddress;
                        OrgChk.OrganizationCode       = model.Org.OrganizationCode.TrimEnd().TrimStart();
                        OrgChk.OrganizationEmail      = model.Org.OrganizationEmail.TrimEnd().TrimStart();
                        OrgChk.OrganizationFrom       = model.Org.OrganizationFrom;
                        OrgChk.OrganizationHomePage   = model.Org.OrganizationHomePage;
                        OrgChk.OrganizationName       = model.Org.OrganizationName.TrimEnd().TrimStart();
                        OrgChk.OrganizationParentCode = model.Org.OrganizationParentCode;
                        OrgChk.OrganizationPhone      = model.Org.OrganizationPhone;
                        OrgChk.OrganizationRemark     = model.Org.OrganizationRemark;
                        OrgChk.OrganizationTaxCode    = model.Org.OrganizationTaxCode.TrimEnd().TrimStart();
                        OrgChk.OrganizationTo         = model.Org.OrganizationTo;
                        OrgChk.OrganizationLogo       = model.Org.OrganizationLogo != null ? model.Org.OrganizationLogo : OrgChk.OrganizationLogo;
                        OrgChk.OrganizationNote       = model.Org.OrganizationNote;
                        OrgChk.OrganizationSphereId   = model.Org.OrganizationSphereId;
                        db.Entry(OrgChk).State        = EntityState.Modified;
                        db.SaveChanges();

                        // Add goi dich vu

                        List <TblOrganizationServicePack> deleteAU = db.TblOrganizationServicePack.Where(au => au.OrganizationId == model.Org.OrganizationId).ToList <TblOrganizationServicePack>();
                        foreach (var item in deleteAU)
                        {
                            db.TblOrganizationServicePack.Remove(item);
                            db.SaveChanges();
                        }
                    }


                    foreach (var item in model.tblServicePack)
                    {
                        TblOrganizationServicePack ru = new TblOrganizationServicePack();
                        ru.OrganizationId = model.Org.OrganizationId;
                        ru.ServicePackId  = item.Id; // id new created
                        db.TblOrganizationServicePack.Add(ru);
                        db.SaveChanges();
                    }


                    result = 2;
                    ts.Complete();
                }


                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                throw ex;
            }
        }
Beispiel #16
0
        /// <summary>
        /// add don vi
        /// </summary>
        /// <param name="Org"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public int AddOrganization(UpdateOrg model, string token)
        {
            int    result  = 0;
            string nameOrg = "";

            try
            {
                TblOrganization OrgChk = db.TblOrganization.Where(r => (r.OrganizationTaxCode == model.Org.OrganizationTaxCode && r.IsDelete == false) || (r.OrganizationCode == model.Org.OrganizationCode && r.IsDelete == false) || (r.OrganizationEmail == model.Org.OrganizationEmail && r.IsDelete == false)).FirstOrDefault();
                if (OrgChk == null)
                {
                    // Send mail
                    string pass     = "";
                    string UserName = "";
                    //HaiHM comment Line under "Pass"
                    //string Pass = User.Password;
                    string UserEmail = "";
                    using (var ts = new TransactionScope())
                    {
                        TblOrganization OrgAdd = new TblOrganization();
                        OrgAdd.IsDelete               = false;
                        OrgAdd.CreateDate             = DateTime.Now;
                        OrgAdd.CreateBy               = model.Org.CreateBy;
                        OrgAdd.IsActive               = model.Org.IsActive;
                        OrgAdd.IsLock                 = model.Org.IsLock;
                        OrgAdd.UpdateBy               = model.Org.UpdateBy;
                        OrgAdd.UpdateDate             = DateTime.Now;
                        OrgAdd.OrganizationAddress    = model.Org.OrganizationAddress;
                        OrgAdd.OrganizationCode       = model.Org.OrganizationCode.TrimEnd().TrimStart();
                        OrgAdd.OrganizationEmail      = model.Org.OrganizationEmail.TrimEnd().TrimStart();
                        OrgAdd.OrganizationFrom       = model.Org.OrganizationFrom;
                        OrgAdd.OrganizationHomePage   = model.Org.OrganizationHomePage;
                        OrgAdd.OrganizationName       = model.Org.OrganizationName.TrimEnd().TrimStart();
                        OrgAdd.OrganizationParentCode = model.Org.OrganizationParentCode;
                        OrgAdd.OrganizationPhone      = model.Org.OrganizationPhone;
                        OrgAdd.OrganizationRemark     = model.Org.OrganizationRemark;
                        OrgAdd.OrganizationTaxCode    = model.Org.OrganizationTaxCode.TrimEnd().TrimStart();
                        OrgAdd.OrganizationTo         = model.Org.OrganizationTo;
                        OrgAdd.OrganizationLogo       = model.Org.OrganizationLogo;
                        OrgAdd.OrganizationNote       = model.Org.OrganizationNote;
                        OrgAdd.OrganizationSphereId   = model.Org.OrganizationSphereId;
                        db.TblOrganization.Add(OrgAdd);
                        db.SaveChanges();

                        nameOrg = OrgAdd.OrganizationName;

                        // ADD admin
                        TblUsers        User = new TblUsers();
                        List <TblUsers> lst  = db.TblUsers.Where(u => u.UserName == model.Org.OrganizationCode + "_Admin").ToList();
                        if (lst != null)
                        {
                            if (lst.Count > 0)
                            {
                                foreach (var item in lst)
                                {
                                    TblUsers users = db.TblUsers.Where(u => u.Id == item.Id).FirstOrDefault();
                                    if (users != null)
                                    {
                                        users.IsDelete        = true;
                                        db.Entry(users).State = EntityState.Modified;
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }
                        User.UserName = model.Org.OrganizationCode + "_Admin";
                        //update isdelete
                        pass = "******";

                        User.Password        = organizationConmon.HashPassword(pass);
                        User.CreateDate      = DateTime.Now;
                        User.IsDelete        = false;
                        User.IsLock          = false;
                        User.CreateBy        = model.Org.CreateBy;
                        User.Email           = model.Org.OrganizationEmail;
                        User.EmailConfirmed  = false;
                        User.HistoryPassword = organizationConmon.HashPassword(pass) + "=";
                        User.LoginFail       = 0;
                        User.LastLogin       = DateTime.Now;
                        User.ExpirationDate  = DateTime.Now.AddDays(OrganizationConstant.ExpirationDate);
                        db.TblUsers.Add(User);
                        db.SaveChanges();
                        int UserID         = User.Id;
                        int OrganizationId = OrgAdd.OrganizationId;

                        // Send mail
                        UserName = User.UserName;
                        //HaiHM comment Line under "Pass"
                        //string Pass = User.Password;
                        UserEmail = User.Email;

                        TblOrganizationUser OrgUser = new TblOrganizationUser
                        {
                            UserId         = UserID,
                            OrganizationId = OrganizationId
                        };
                        db.TblOrganizationUser.Add(OrgUser);
                        db.SaveChanges();

                        //ADD goi dich vu

                        foreach (var item in model.tblServicePack)
                        {
                            TblOrganizationServicePack ru = new TblOrganizationServicePack();
                            ru.OrganizationId = OrganizationId;
                            ru.ServicePackId  = item.Id; // id new created
                            db.TblOrganizationServicePack.Add(ru);
                            db.SaveChanges();
                        }



                        //HaiHM modified
                        AddAuthorityAndRoleForUserAdmin(OrganizationId, model.Org.CreateBy, UserID);

                        ts.Complete();
                    }
                    if (!string.IsNullOrEmpty(UserEmail))
                    {
                        SendMail(nameOrg, UserEmail, UserName, pass, "");
                        result = 1;
                        GenerateDB(model.Org.OrganizationCode, token);
                    }
                }
                else
                {
                    if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationCode == model.Org.OrganizationCode).Count() > 0)
                    {
                        // Duplicate AddDuplicateOrgCode
                        return(result = 411);
                    }

                    if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationEmail == model.Org.OrganizationEmail).Count() > 0)
                    {
                        // Duplicate AddDuplicateEmail
                        return(result = 412);
                    }

                    if (db.TblOrganization.Where(u => u.IsDelete == false && u.OrganizationTaxCode == model.Org.OrganizationTaxCode).Count() > 0)
                    {
                        // Duplicate AddDuplicateOrgTaxCode
                        return(result = 413);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                throw ex;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Delete Organization
        /// </summary>
        /// <param name="OrganizationId"></param>
        /// <returns></returns>

        public int DeleteOrganization(int OrganizationId)
        {
            int result = 0;

            try
            {
                var lstOrgCheck = (from a in db.TblOrganizationUser
                                   join b in db.TblUsers on a.UserId equals b.Id
                                   where b.IsDelete == false && a.OrganizationId == OrganizationId
                                   select new
                {
                    b.Id
                });

                if (lstOrgCheck.Count() > 1)
                {
                    result = 0;
                }
                else
                {
                    using (var ts = new TransactionScope())
                    {
                        TblOrganization OrgChk = db.TblOrganization.Where(a => a.OrganizationId == OrganizationId).FirstOrDefault();
                        if (OrgChk != null)
                        {
                            OrgChk.IsDelete        = true;
                            db.Entry(OrgChk).State = EntityState.Modified;
                            db.SaveChanges();

                            TblConnectionConfig connect = db.TblConnectionConfig.Where(a => a.ConnectionKey == OrgChk.OrganizationCode + "Connection").FirstOrDefault();
                            if (connect != null)
                            {
                                db.TblConnectionConfig.Remove(connect);
                                db.SaveChanges();
                            }

                            string urlImage = _environment.WebRootPath + OrganizationConstant.DirectoryUploads + OrgChk.OrganizationCode + "\\" + OrgChk.OrganizationCode + ".png";
                            try
                            {
                                File.Delete(urlImage);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }

                            DeleteUser(OrganizationId);

                            result = 1;
                        }
                        ts.Complete();
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                throw ex;
            }
        }