예제 #1
0
 /// <summary>
 /// AddUpdateCurrentUser method
 /// </summary>
 /// <param name="asppUser"></param>
 /// <param name="asppGroups"></param>
 /// <param name="simplUser"></param>
 /// <param name="db"></param>
 public void AddUpdateCurrentUser(ASPP_Users asppUser, List<ASPP_Groups> asppGroups, Entity simplUser, SIMPLEntities db)
 {
     // import user information from ASPP db
     simplUser.EntityName1 = asppUser.Last_Name;
     simplUser.EntityName2 = asppUser.First_Name;
     simplUser.EntityTypeId = DetermineEntityType(asppUser, asppGroups, db);
     if (simplUser.EntityTypeId == 0)
         throw new ASPPException("No roles defined for user");
     simplUser.Cbr = asppUser.Phone != null ? Regex.Replace(asppUser.Phone, "[^0-9]", "") : "";
     simplUser.Email = asppUser.Email;
 }
예제 #2
0
 public static string ToSimplEntityId(int id, SIMPLEntities db)
 {
     try
     {
         var uniqueId = db.UniqueIds.FirstOrDefault(u => u.EntityId == id);
         if (uniqueId != null)
         {
             var returnValue = uniqueId.UniqueIdValue + "-" + id.ToString(CultureInfo.InvariantCulture);
             return returnValue;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error converting to SIMPL entity id.", ex);
     }
     return null;
 }
예제 #3
0
        public SimplOrder(Order order, SIMPLEntities db)
        {
            if (order == null)
            {
                throw new ArgumentNullException();
            }

            const int custEntId = 8;
            try
            {
                var master = db.MasterOrders.FirstOrDefault(m => m.MasterOrderId == order.MasterOrderId);
                var uniqueId = db.UniqueIds.FirstOrDefault(u => u.EntityId == master.CreatingEntityId);
                if (uniqueId != null)
                    CreatorId = uniqueId.UniqueIdValue;
                if (master != null && master.ReceivingEntityId != custEntId)
                {
                    var id = db.UniqueIds.FirstOrDefault(u => u.EntityId == master.ReceivingEntityId);
                    if (id != null)
                        ReceiverId = id.UniqueIdValue;
                }
                else
                {
                    var addr = db.ShipAddresses.FirstOrDefault(s => s.ShipAddressId ==
                                                                            db.Orders.FirstOrDefault(o => o.OrderId == order.OrderId).ShipAddress.Value);
                    ReceiverId = (addr != null) ? addr.SubscriberId : "Subscriber";
                }
                if (master != null) CreateDateTime = master.CreateDateTime;
                MasterOrderId = order.MasterOrderId.ToString(CultureInfo.InvariantCulture);
                OrderId = order.OrderId.ToString(CultureInfo.InvariantCulture);
                var location = db.Locations.FirstOrDefault(l => l.TriadLocId == order.Location.TriadLocId);
                if (location != null)
                    FillLocation = location.TriadLocId;
                FilledBy = order.FilledByEntityId != null ? StaticSimplFormats.ToSimplEntityId(Convert.ToInt32(order.FilledByEntityId), db) : null;
                FillDateTime = order.FilledDateTime;
                var trackingNumber = order.TrackingNumbers.FirstOrDefault();
                if (trackingNumber != null)
                    TrackingNumber = trackingNumber.TrackingNumber1;
            }
            catch (Exception ex)
            {
                throw new Exception("Error creating SIMPL order from order. (See InnerException for more info.)", ex);
            }
        }
예제 #4
0
 public SimplTransaction(Transaction transaction, SIMPLEntities db)
 {
     TransactionId = transaction.TransactionId;
     var transactionType = DBCache.TransactionTypes.FirstOrDefault(t => t.TransactionTypeId == transaction.TransactionType);
     if (transactionType != null)
         TransactionType = transactionType.TransactionTypeName;
     var equipmentType = DBCache.EquipmentTypes.FirstOrDefault(e => e.EquipmentTypeId == transaction.EquipTypeId);
     if (equipmentType != null)
         EquipType = equipmentType.ModelNumber;
     SerialNumber = transaction.SerialNumber;
     var uniqueId = db.UniqueIds.FirstOrDefault(uid => uid.EntityId == transaction.ActionEntityId);
     if (uniqueId != null)
         ActionEntity = uniqueId.UniqueIdValue + "-" + transaction.ActionEntityId;
     OriginalLoc = transaction.OriginalLocId ?? "";
     UpdatedLoc = transaction.UpdatedLocId;
     TransactionTime = transaction.TransactionTime;
     var transactionResultType = DBCache.TransactionResultTypes.FirstOrDefault(t => t.ResultTypeId == transaction.ResultTypeId);
     if (transactionResultType != null)
         ResultType = transactionResultType.ResultTypeName;
 }
예제 #5
0
        /// <summary>
        /// DetermineEntityType method
        /// </summary>
        /// <param name="user"></param>
        /// <param name="asppGroups"></param>
        /// <param name="sdb"></param>
        /// <returns></returns>
        public int DetermineEntityType(ASPP_Users user, IEnumerable<ASPP_Groups> asppGroups, SIMPLEntities sdb)
        {
            var groupIdList = asppGroups.Select(g => g.Group_ID).ToList();

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Admin))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Admin;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.FieldMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.FieldMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.NTElevated))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.NTElevated;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.NT))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.NT;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairHelpdesk))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairHelpdesk;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesHelpdesk))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesHelpdesk;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Collections))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Collections;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Distributor))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Distributor;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Retail))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Retail;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Supply))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Supply;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Tech))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Tech;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairAgent))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairAgent;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesAgent))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesAgent;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.ReadOnly))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.ReadOnly;
            }

            return 0;
        }
예제 #6
0
 /// <summary>
 /// ToggleActiveRoles method
 /// </summary>
 /// <param name="simplRoles"></param>
 /// <param name="currentAsppRoles"></param>
 /// <param name="simplUser"></param>
 /// <param name="sdb"></param>
 public void ToggleActiveRoles(IEnumerable<UserRole> simplRoles, List<int> currentAsppRoles, Entity simplUser, SIMPLEntities sdb)
 {
     // for each role in simpl db make active if current in ASPP, otherwise make inactive
     foreach (var role in simplRoles)
     {
         role.IsActive = currentAsppRoles.Contains(role.RoleType);
     }
 }
예제 #7
0
        /// <summary>
        /// SyncUniqueId method
        /// </summary>
        /// <param name="simplUser"></param>
        /// <param name="db"></param>
        /// <param name="userId"></param>
        public void SyncUniqueId(Entity simplUser, SIMPLEntities db, string userId)
        {
            //see if id exists in unique ids table. if not, add it
            var id = db.UniqueIds.FirstOrDefault(u => u.UniqueIdValue == userId);
            if (id != null) return;

            id = new UniqueId
            {
                EntityId = simplUser.EntityId,
                UniqueIdTypeId = RegexValidator.DetermineUniqueIdType(userId),
                UniqueIdValue = userId
            };
            db.UniqueIds.AddObject(id);
        }
예제 #8
0
        /// <summary>
        /// Updates (via inserting new rows or deactivating current rows) the simpl db roleTypes table with a users current permissions,
        /// which are based on the ASPP_Users GroupList
        /// </summary>
        /// <param name="asppGroups"></param>
        /// <param name="simplUser"></param>
        /// <param name="db"></param>
        public void SyncRoles(IEnumerable<ASPP_Groups> asppGroups, Entity simplUser, SIMPLEntities db)
        {
            // get aspp groupd IDs and translate to SIMPL roles in SIMPL db
            var asppGroupIntegers = asppGroups.Select(g => g.Group_ID).ToList();

            // populate list of simpl roles that correlate to CURRENT group assignments in ASPP.
            var myCurrentRoleTypes = db.ASPPGroupsTranslations.Where(r => asppGroupIntegers
                .Contains(r.ASPP_Group_Id)).Select(r => r.SIMPL_RoleType_Id).ToList();

            // If no roles exist for user, insert all, else do partial insert, trim removed roles, and add new ones
            if (db.UserRoles.Count(u => u.EntityId == simplUser.EntityId) <= 0)
            {
                // no roles exist, so insert all
                InsertSimplRoles(myCurrentRoleTypes, simplUser, db);
            }
            else
            {
                // Roles currently exist, so do a partial insert of translated groupIds which don't exist in UserRoles table, activate, then deactivate
                // First, get list of roles coming from ASPP not currently in SIMPL db
                var simplRoles = db.UserRoles.Where(r => r.EntityId == simplUser.EntityId).ToList();
                var simplRoleIds = simplRoles.Select(r => r.RoleType).ToList();
                var roleIdsToInsert = myCurrentRoleTypes.Where(i => !simplRoleIds.Contains(i)).ToList();

                // then, perform updates
                InsertSimplRoles(roleIdsToInsert, simplUser, db);
                ToggleActiveRoles(simplRoles, myCurrentRoleTypes, simplUser, db);
            }
        }
예제 #9
0
        /// <summary>
        /// Updates the integer LocId value on an Entity entity based on the company_name
        /// field in the ASPP_Users database via a translation table in the simpl db
        /// </summary>
        /// <param name="asppUser"></param>
        /// <param name="simplUser"></param>
        /// <param name="db"></param>
        public void SyncLocation(ASPP_Users asppUser, Entity simplUser, SIMPLEntities db)
        {
            var loc = db.ASPPLocTranslations.FirstOrDefault(l => l.ASPP_Loc == asppUser.Company_Name);
            if (loc == null)
                // User's aspp_location does not exist in the simpl translation table, so throw error and stop run.
                throw new ASPPException("User's location does not exist/is out-of-date. Please submit a support ticket to resolve.");

            // User's aspp_location exists in translation table, so set loc_id to corresponding simpl LocId (int)
            simplUser.LocId = loc.SIMPL_LocId;
        }
예제 #10
0
 /// <summary>
 /// InsertSimplRoles method
 /// </summary>
 /// <param name="simplRoleList"></param>
 /// <param name="simplUser"></param>
 /// <param name="sdb"></param>
 public void InsertSimplRoles(IEnumerable<int> simplRoleList, Entity simplUser, SIMPLEntities sdb)
 {
     foreach (var roleTypeId in simplRoleList)
     {
         var newRole = new UserRole { EntityId = simplUser.EntityId, RoleType = roleTypeId, IsActive = true };
         sdb.UserRoles.AddObject(newRole);
     }
 }
예제 #11
0
        public void Send(DefinedEmailType emailType, IEnumerable<string> addresses = null, ItxOrder itxOrder = null, int masterOrderId = 0, string userEmail = "", EquipmentCriteriaDto criteria = null, string manufacturer = null, Dictionary<string, string> migrationParams = null)
        {
            var message     = new MailMessage();
            var client      = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], 25);
            var body        = new StringBuilder();
            message.From    = new MailAddress(ConfigurationManager.AppSettings["SupportEmail"]);

            // Add a CC list if this is not a CreateONT call
            if(!emailType.Equals(DefinedEmailType.CreateONT))
            {
                // add user defined email addresses in "CC" field
                if (addresses != null)
                {
                    foreach (var address in addresses.Where(address => !message.CC.Select(cc => cc.Address).Contains(address)))
                    {
                        message.CC.Add(new MailAddress(address));
                    }
                }
                // add the logged-in user as a CC
                if (!message.CC.Select(cc => cc.Address).Contains(userEmail))
                {
                    message.CC.Add(new MailAddress(userEmail));
                }
            }

            // define message body and subject depending on the type of email being sent
            switch (emailType)
            {
                case DefinedEmailType.DropshipCancellationRequest:
                    body.AppendLine("A SIMPL production support person has requested that a dropship order be cancelled.");
                    body.AppendLine();
                    if (itxOrder != null && masterOrderId != 0)
                    {
                        body.AppendLine("The order information is:");
                        body.AppendLine(string.Format("Subscriber Name: {0}", itxOrder.ShipName1 + " " + itxOrder.ShipName2));
                        body.AppendLine(string.Format("Phone Number: {0}", "0" + masterOrderId));
                        body.AppendLine(string.Format("Address: {0}, {1} {2}, {3}, {4}",
                            itxOrder.ShipAddress1,
                            string.IsNullOrEmpty(itxOrder.ShipAddress2) ? "" : (itxOrder.ShipAddress2 + ","),
                            itxOrder.ShipCity,
                            itxOrder.ShipState,
                            itxOrder.ShipZip));
                        body.AppendLine();
                        body.AppendLine(string.Format("Uploaded to DSL Order Tool server: {0}", itxOrder.SentDateTime));
                    }
                    else
                    {
                        body.AppendLine("Please review this dropship cancellation attempt since the order information was missing from this request.");
                    }
                    body.AppendLine();
                    body.AppendLine("Please use \"Reply to All\" when forwarding or responding to this message.");

                    message.Subject = "Dropship order cancellation request";

                    // add email addresses for those who are responsible for order cancellation in "To" field
                    var toAddresses = GetRecipients("DropshipCancelEmailList");
                    foreach (var address in toAddresses)
                    {
                        message.To.Add(address.Trim());
                    }
                    break;

                case DefinedEmailType.DropshipCancelledInSimplDB:

                    if (masterOrderId != 0)
                    {
                        body.AppendLine("The order has been successfully cancelled in SIMPL");

                        Entity requestor;
                        using (var db = new SIMPLEntities())
                        {
                            requestor = db.Entities.FirstOrDefault(
                                e => e.EntityId == db.MasterOrders.FirstOrDefault(m => m.MasterOrderId == masterOrderId).CreatingEntityId);
                        }
                        if (requestor != null)
                        {
                            message.CC.Add(new MailAddress(requestor.Email));
                        }
                    }
                    else
                    {
                        body.AppendLine("An order cancellation may not have been processed due to a missing masterOrderId. Please investigate.");
                    }
                    break;

                case DefinedEmailType.CreateONT:
                    if (criteria != null)
                    {
                        var mfr = !string.IsNullOrEmpty(manufacturer) ? manufacturer : "Unknown";
                        body.AppendLine("Triad support,");
                        body.AppendLine();
                        body.AppendLine("An ONT/RG has been created in SIMPL with the following information:");
                        body.AppendLine("Manufacturer: " + mfr);
                        body.AppendLine("Model: " + criteria.Model);
                        body.AppendLine("Serial Number: "+ criteria.SerialNumber);
                        body.AppendLine("Created by: " + userEmail);
                        body.AppendLine("Date: " + System.DateTime.Now.ToString());
                        body.AppendLine();
                        body.AppendLine("Please verify other associated serial numbers have been added to Triad.");
                    }
                    else
                    {
                        body.AppendLine("An ONT has been created but the equipment information was left out from the notification. Please investigate.");
                    }
                    message.To.Add(new MailAddress(ConfigurationManager.AppSettings["SupportEmail"]));
                    message.Subject = "Create ONT/RG confirmation";
                    break;

                case DefinedEmailType.MigrateSTB:
                    if (migrationParams != null && migrationParams.Count > 0)
                    {
                        foreach (var migrationParam in migrationParams)
                        {
                            body.AppendLine(string.Format("{0}:{1}", migrationParam.Key, migrationParam.Value));
                            body.AppendLine();
                        }

                        message.Subject = "ATT STB Migration Notification";

                    }

                    // add email addresses for those who are responsible for order cancellation in "To" field
                    foreach (var address in GetRecipients("MigrateStbEmailList"))
                    {
                        message.To.Add(address.Trim());
                    }

                    break;

                case DefinedEmailType.MigrateVOIP:
                     if (migrationParams != null && migrationParams.Count > 0)
                    {
                        foreach (var migrationParam in migrationParams)
                        {
                            body.AppendLine(string.Format("{0}:{1}", migrationParam.Key, migrationParam.Value));
                            body.AppendLine();
                        }

                        message.Subject = "ATT VOIP Migration Notification";

                    }

                    // add email addresses for those who are responsible for order cancellation in "To" field
                    foreach (var address in GetRecipients("MigrateVoipEmailList"))
                    {
                        message.To.Add(address.Trim());
                    }

                    break;
            }
            // add a signature
            body.AppendLine();
            body.AppendLine("Thanks!");
            body.AppendLine();
            body.AppendLine("SIMPL auto-mailer");

            message.Body = body.ToString();

            // send the message
            client.Send(message);
        }
예제 #12
0
 //public bool ExistsAtLocId(string serialNumber)
 //{
 //    Transaction value = _context.Transactions.OrderByDescending(t => t.TransactionId).FirstOrDefault(tid => tid.SerialNumber == serialNumber && tid.TransactionType == 1);
 //    return (value != null && value.UpdatedLocId == CurrentUser.GetInstance().UserLocation.LocId);
 //}
 public static bool ExistsAtLocId(string serialNumber, string triadLocId, SIMPLEntities db)
 {
     var value = db.Transactions.OrderByDescending(t => t.TransactionId).FirstOrDefault(tid => tid.SerialNumber == serialNumber && tid.TransactionType == 1);
     return (value != null && value.UpdatedLocId == triadLocId);
 }
예제 #13
0
 public EfQueries()
 {
     if (_context == null)
         _context = DBContextFactory.CreateContext();
 }
예제 #14
0
 public void Reopen()
 {
     if (_context == null)
         _context = DBContextFactory.CreateContext();
 }
예제 #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// 
 public SimplFormats()
 {
     if (_context == null)
         _context = DBContextFactory.CreateContext();
 }