コード例 #1
0
        private void CheckPostalCodePostageCharges()
        {
            var eventDetail = db.SystemEvents.Find(Generic.SystemEventCheckPostal);
            if (eventDetail != null && eventDetail.UserId.HasValue)
            {
                var codes = db.PostalCodes.Where(m=>m.Active).ToArray();
                foreach (var code in codes)
                {
                    var charge = (from item in db.PostalCodePostageCharges
                                  where item.PostalCodeId == code.PostalCodeId
                                  select item).FirstOrDefault();
                    if (charge == null)
                    {
                        var msg = string.Format("Postal code {0} does not have a postage charge set up", code.PostalCodeName);

                        //create a note
                        var note = (from item in db.SystemNotes
                                    where item.NoteText == msg
                                    select item).FirstOrDefault();

                        if (note == null)
                        {
                            int clientId = 0;
                            var clientIds = (from item in db.Addresses
                                            where item.Code == code.PostalCodeName
                                            select item.ClientID).ToArray();

                            if (clientIds.Length > 0) clientId = clientIds.Max();

                            if (clientId > 0)
                            {
                                note = new SystemNote()
                                {
                                    UserID = eventDetail.UserId.Value,
                                    Created = DateTime.Now,
                                    NoteId = Guid.NewGuid(),
                                    NoteText = msg
                                };
                                db.SystemNotes.Add(note);
                                db.SaveChanges();


                                SystemTicketTemplatesController.PersistTicket(db, Generic.SystemEventCheckPostal,
                                    note.NoteId,
                                    clientId,
                                    Generic.SupportTicketTypeIdSystem,
                                    msg,
                                    eventDetail.UserId.Value);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void CheckPostalCodes()
        {

            var eventDetail = db.SystemEvents.Find(Generic.SystemEventCheckPostal);
            if (eventDetail != null && eventDetail.UserId.HasValue)
            {
                var clientPostalCodes = (from item in db.Addresses
                                         where item.AddressTypeID == 2
                                         && item.ClientID>0
                                         select item).ToArray();
                var clientPostalCodeGrouped = (from item in clientPostalCodes
                                               group item by item.Code into grp
                                               select grp).ToArray();


                foreach (var grouped in clientPostalCodeGrouped)
                {
                    var code = (from item in db.PostalCodes
                                where item.PostalCodeName == grouped.Key
                                select item).FirstOrDefault();
                    if (code == null)
                    {

                        var msg = string.Format("Postal code \"{0}\" does not exist but is used by {1} client(s) as a shipping address code. First client: {2}", grouped.Key, grouped.Count(), grouped.First().ClientID);

                        //create a note
                        var note = (from item in db.SystemNotes
                                    where item.NoteText == msg
                                    select item).FirstOrDefault();

                        if (note == null)
                        {
                            note = new SystemNote()
                            {
                                UserID = eventDetail.UserId.Value,
                                Created = DateTime.Now,
                                NoteId = Guid.NewGuid(),
                                NoteText = msg
                            };
                            db.SystemNotes.Add(note);
                            db.SaveChanges();

                            SystemTicketTemplatesController.PersistTicket(db, Generic.SystemEventCheckPostal,
                                note.NoteId,
                                grouped.First().ClientID,
                                Generic.SupportTicketTypeIdSystem,
                                msg,
                                eventDetail.UserId.Value);

                        }
                    }
                }
            }
        }