Beispiel #1
0
        public void TestTree()
        {
            MyDB mydb = new MyDB();

            OrganizationExt m = mydb.OrganizationExts.FirstOrDefault();

            Debug.WriteLine(m.Name);
        }
Beispiel #2
0
        public (Guid organizationId, Guid employeeId, Guid profileId, Guid personId) SaveSignIn(SignInEditModel model,
                                                                                                string path)
        {
            var organization = new OrganizationExt();

            if (!string.IsNullOrEmpty(model.EDRPOU))
            {
                organization = _context.Organizations.FirstOrDefault(x => x.EDRPOU == model.EDRPOU);
            }
            else
            {
                organization = null;
            }

            if (organization == null)
            {
                organization = new OrganizationExt
                {
                    Name   = model.Name,
                    EDRPOU = model.EDRPOU,
                    EMail  = model.OrgEmail,
                    INN    = !string.IsNullOrEmpty(model.EDRPOU) ? null : model.INN
                };

                _context.Add_Auditable(organization);
                _context.SaveChanges();

                var licenses = _limsService.GetLicenses("",
                                                        !string.IsNullOrEmpty(model.EDRPOU) ? model.EDRPOU : model.INN).Result;

                var trlLicenseIds = new List <string> {
                    "2", "3", "4"
                };

                var orgInfoPRL = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "PRL",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Contains("1"))
                };
                var orgInfoIML = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "IML",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.FirstOrDefault(x => x.LicenseTypesIds.Contains("5")) != null
                };
                var orgInfoTRL = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "TRL",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Split("|").Any(y => trlLicenseIds.Contains(y)))
                };
                _context.AddRange_Auditable(orgInfoPRL, orgInfoIML, orgInfoTRL);
                _context.SaveChanges();

                //TODO email
            }

            var person = _context.Person.FirstOrDefault(x => x.IPN == model.INN && x.LastName == model.LastName);

            if (person == null)
            {
                person = new Person
                {
                    LastName   = model.LastName,
                    MiddleName = model.MiddleName,
                    Name       = model.UserName,
                    Phone      = model.UserPhone,
                    IPN        = model.INN,
                    Email      = model.UserEmail,
                    Birthday   = DateTime.MinValue,
                    Caption    = $"{model.LastName} {model.UserName} {model.MiddleName}"
                };
                _context.Add_Auditable(person);
                _context.SaveChanges();
            }

            var employees = _context.EmployeesExt.Where(x => x.PersonId == person.Id)
                            .Include(x => x.DefaultValues)
                            .Include(x => x.Profiles)
                            .ToList();
            var employeeOrg = employees.FirstOrDefault(x => x.OrganizationId == organization.Id);
            var profile     = _context.Profiles.FirstOrDefault(x => x.Caption == "Employee");

            if (employeeOrg != null)
            {
                employeeOrg.Position  = model.Position;
                employeeOrg.UserEmail = model.UserEmail;
                employeeOrg.ReceiveOnChangeAllMessage     = model.ReceiveOnChangeAllMessage;
                employeeOrg.ReceiveOnChangeOwnMessage     = model.ReceiveOnChangeOwnMessage;
                employeeOrg.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication;
                employeeOrg.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication;
                employeeOrg.PersonalCabinetStatus         = model.PersonalCabinetStatus;
                employeeOrg.ReceiveOnChangeOrgInfo        = model.ReceiveOnChangeOrgInfo;
                employeeOrg.ReceiveOnOverduePayment       = model.ReceiveOnOverduePayment;

                try
                {
                    if (employeeOrg.DefaultValues.FirstOrDefault()?.ValueId != organization.Id)
                    {
                        employeeOrg.DefaultValues = new List <UserDefaultValue>
                        {
                            new UserDefaultValue
                            {
                                Caption    = person.Caption,
                                EntityName = nameof(OrganizationExt),
                                ValueId    = organization.Id
                            }
                        };
                    }
                }
                catch (Exception)
                {
                    if (employeeOrg.DefaultValues.Any())
                    {
                        employeeOrg.DefaultValues = new List <UserDefaultValue>
                        {
                            new UserDefaultValue
                            {
                                Caption    = person.Caption,
                                EntityName = nameof(OrganizationExt),
                                ValueId    = organization.Id
                            }
                        };
                    }
                }

                if (employeeOrg.Profiles.Any())
                {
                    employeeOrg.Profiles = new List <UserProfile>
                    {
                        new UserProfile
                        {
                            ProfileId = profile.Id,
                            Caption   = $"{profile.Caption}: {person.Caption}"
                        }
                    };
                }

                _context.SaveChanges();
                if (employeeOrg.UserEmail != model.UserEmail)
                {
                    //TODO Email
                }
            }
            else
            {
                employeeOrg = new EmployeeExt
                {
                    PersonId  = person.Id,
                    Position  = model.Position,
                    UserEmail = model.UserEmail,
                    ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication,
                    ReceiveOnChangeAllMessage     = model.ReceiveOnChangeAllMessage,
                    ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication,
                    ReceiveOnChangeOwnMessage     = model.ReceiveOnChangeOwnMessage,
                    PersonalCabinetStatus         = model.PersonalCabinetStatus,
                    ReceiveOnChangeOrgInfo        = model.ReceiveOnChangeOrgInfo,
                    ReceiveOnOverduePayment       = model.ReceiveOnOverduePayment,
                    OrganizationId = organization.Id,
                    DefaultValues  = new List <UserDefaultValue>
                    {
                        new UserDefaultValue
                        {
                            Caption    = person.Caption,
                            EntityName = nameof(OrganizationExt),
                            ValueId    = organization.Id
                        }
                    },
                    Profiles = new List <UserProfile>
                    {
                        new UserProfile
                        {
                            ProfileId = profile.Id,
                            Caption   = $"{profile.Caption}: {person.Caption}"
                        }
                    }
                };
                _context.Add_Auditable(employeeOrg);
                _context.SaveChanges();
                //TODO Email
            }

            return(organization.Id, employeeOrg.Id, profile.Id, person.Id);
        }
Beispiel #3
0
        public IActionResult InfoUpdate(UserAreaDetailDTO model)
        {
            var isChangedOrg      = false;
            var isChangedEmployee = false;
            var isChangedPerson   = false;

            var userInfo           = _userInfoService.GetCurrentUserInfo();
            var userEmployeeEntity = new EmployeeExt();
            var userPersonEntity   = new Person();
            var userOrgEntity      = new OrganizationExt();

            try
            {
                Guid personGuid = userInfo.PersonId;
                userEmployeeEntity = _commonDataService.GetEntity <EmployeeExt>(org_employee => (org_employee.PersonId == userInfo.PersonId)).FirstOrDefault();
                userPersonEntity   = _commonDataService.GetEntity <Person>(person => (person.Id == userInfo.PersonId)).FirstOrDefault();
                userOrgEntity      = _commonDataService.GetEntity <OrganizationExt>(org_organization => (org_organization.Id == userEmployeeEntity.OrganizationId)).FirstOrDefault();
            }
            catch
            {
                return(NotFound());
            }

            // должность
            if (!string.IsNullOrEmpty(model.Position) && (model.Position != userEmployeeEntity.Position))
            {
                isChangedEmployee           = true;
                userEmployeeEntity.Position = model.Position;
            }

            // мейл пользователя
            if (!string.IsNullOrEmpty(model.UserEmail) && (model.UserEmail != userEmployeeEntity.UserEmail))
            {
                isChangedEmployee            = true;
                userEmployeeEntity.UserEmail = model.UserEmail;
            }

            // мейл компании
            if (!string.IsNullOrEmpty(model.OrgEmail) && (model.OrgEmail != userOrgEntity.EMail))
            {
                isChangedOrg        = true;
                userOrgEntity.EMail = model.OrgEmail;
            }

            // телефон пользователя
            if (!string.IsNullOrEmpty(model.Phone) && (model.Phone != userPersonEntity.Phone))
            {
                isChangedPerson        = true;
                userPersonEntity.Phone = model.Phone;
            }

            // оповещение ReceiveOnChangeAllApplication
            if (model.ReceiveOnChangeAllApplication != userEmployeeEntity.ReceiveOnChangeAllApplication)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication;
            }

            // оповещение ReceiveOnChangeAllMessage
            if (model.ReceiveOnChangeAllMessage != userEmployeeEntity.ReceiveOnChangeAllMessage)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage;
            }

            // оповещение ReceiveOnChangeOwnApplication
            if (model.ReceiveOnChangeOwnApplication != userEmployeeEntity.ReceiveOnChangeOwnApplication)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication;
            }

            // оповещение ReceiveOnChangeOwnMessage
            if (model.ReceiveOnChangeOwnMessage != userEmployeeEntity.ReceiveOnChangeOwnMessage)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage;
            }

            // оповещение PersonalCabinetStatus - TODO - переименовать
            if (model.PersonalCabinetStatus != userEmployeeEntity.PersonalCabinetStatus)
            {
                isChangedEmployee = true;
                userEmployeeEntity.PersonalCabinetStatus = model.PersonalCabinetStatus;
            }

            // оповещение ReceiveOnChangeOrgInfo - TODO - добавить в модель
            if (model.ReceiveOnChangeOrgInfo != userEmployeeEntity.ReceiveOnChangeOrgInfo)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo;
            }

            // оповещение ReceiveOnOverduePayment - TODO - добавить в модель
            if (model.ReceiveOnOverduePayment != userEmployeeEntity.ReceiveOnOverduePayment)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnOverduePayment = model.ReceiveOnOverduePayment;
            }

            try
            {
                if (isChangedPerson)
                {
                    _commonDataService.Add(userPersonEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (персона)!" }));
            }

            try
            {
                if (isChangedEmployee)
                {
                    _commonDataService.Add(userEmployeeEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (співробітник)!" }));
            }

            try
            {
                if (isChangedOrg)
                {
                    _commonDataService.Add(userOrgEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (організація)!" }));
            }

            if (isChangedPerson || isChangedEmployee || isChangedOrg)
            {
                _commonDataService.SaveChanges();
            }

            return(Json(new { success = true, errortext = "Зміна даних користувача пройшла успішно!" }));
        }