Exemple #1
0
        private void CreateTracking(Shipment shipment)
        {
            var order            = shipment.Order;
            var customer         = shipment.Order.Customer;
            var customerFullName = string.Format("{0} {1}", order.ShippingAddress.FirstName, order.ShippingAddress.LastName).Trim();

            //create the new tracking
            var track = new Aftership.Tracking(shipment.TrackingNumber)
            {
                CustomerName = customerFullName,
                OrderId      = string.Format("ID {0}", order.Id),
                OrderIdPath  = string.Format("{0}orderdetails/{1}", _storeContext.CurrentStore.Url, order.Id)
            };

            if (_settings.AllowCustomerNotification)
            {
                track.Emails = new List <string> {
                    customer.Email
                };
            }

            try
            {
                track = _connection.CreateTracking(track);
                _genericAttributeService.InsertAttribute(new GenericAttribute
                {
                    EntityId = shipment.Id,
                    Key      = Constants.SHIPMENT_NOTIFICATION_ATTRIBUTE_NAME,
                    KeyGroup = "Shipment",
                    StoreId  = 0,
                    Value    = "True"
                });
                _genericAttributeService.InsertAttribute(new GenericAttribute
                {
                    EntityId = shipment.Id,
                    Key      = Constants.SHIPMENT_TRACK_NUMBER_ATTRIBUTE_NAME,
                    KeyGroup = "Shipment",
                    StoreId  = 0,
                    Value    = shipment.TrackingNumber
                });
                _genericAttributeService.InsertAttribute(new GenericAttribute
                {
                    EntityId = shipment.Id,
                    Key      = Constants.SHIPMENT_TRACK_ID_ATTRIBUTE_NAME,
                    KeyGroup = "Shipment",
                    StoreId  = 0,
                    Value    = track.Id
                });
            }
            catch (WebException ex)
            {
                _logger.Error(
                    string.Format("Cannot registration tracking with number - {0}", shipment.TrackingNumber),
                    new Exception(ex.Message));
            }
        }
        public ActionResult GenericAttributeAdd(GenericAttributeModel model, GridCommand command)
        {
            if (_services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel))
            {
                model.Key   = model.Key.TrimSafe();
                model.Value = model.Value.TrimSafe();

                if (!ModelState.IsValid)
                {
                    var modelStateErrorMessages = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                    return(Content(modelStateErrorMessages.FirstOrDefault()));
                }

                var storeId = _services.StoreContext.CurrentStore.Id;

                var attr = _genericAttributeService.GetAttribute <string>(model.EntityName, model.EntityId, model.Key, storeId);
                if (attr == null)
                {
                    _genericAttributeService.InsertAttribute(new GenericAttribute
                    {
                        StoreId  = storeId,
                        KeyGroup = model.EntityName,
                        EntityId = model.EntityId,
                        Key      = model.Key,
                        Value    = model.Value
                    });
                }
                else
                {
                    return(Content(T("Admin.Common.GenericAttributes.NameAlreadyExists", model.Key)));
                }
            }

            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
        }
        public void ShouldSetCreatedOrUpdatedDateUtcInInsertAttribute()
        {
            var attribute = new Core.Domain.Common.GenericAttribute
            {
                Key = "test", KeyGroup = "test", Value = "test", CreatedOrUpdatedDateUTC = null
            };

            _genericAttributeService.InsertAttribute(attribute);

            var createdOrUpdatedDate = attribute.CreatedOrUpdatedDateUTC;

            _genericAttributeService.DeleteAttribute(attribute);

            Assert.That(createdOrUpdatedDate,
                        Is.EqualTo(DateTime.UtcNow).Within(1).Minutes);
        }
        public void Should_Set_CreatedOrUpdatedDateUTC_In_InsertAttribute()
        {
            var attribute = new Core.Domain.Common.GenericAttribute
            {
                Key = "test",
                CreatedOrUpdatedDateUTC = null
            };

            _genericAttributeService.InsertAttribute(attribute);

            Assert.That(attribute.CreatedOrUpdatedDateUTC,
                        Is.EqualTo(DateTime.UtcNow).Within(1).Minutes);
        }
        public ActionResult GenericAttributeAdd(GenericAttributeModel model, GridCommand command)
        {
            model.Key   = model.Key.TrimSafe();
            model.Value = model.Value.TrimSafe() ?? string.Empty;

            if (ModelState.IsValid)
            {
                var storeId = _services.StoreContext.CurrentStore.Id;
                var infos   = GetGenericAttributesInfos(model.EntityName);
                if (infos.UpdatePermission.HasValue() && !Services.Permissions.Authorize(infos.UpdatePermission))
                {
                    NotifyError(Services.Permissions.GetUnauthorizedMessage(infos.UpdatePermission));
                }
                else
                {
                    var attr = _genericAttributeService.GetAttribute <string>(model.EntityName, model.EntityId, model.Key, storeId);
                    if (attr == null)
                    {
                        _genericAttributeService.InsertAttribute(new GenericAttribute
                        {
                            StoreId  = storeId,
                            KeyGroup = model.EntityName,
                            EntityId = model.EntityId,
                            Key      = model.Key,
                            Value    = model.Value
                        });
                    }
                    else
                    {
                        NotifyWarning(T("Admin.Common.GenericAttributes.NameAlreadyExists", model.Key));
                    }
                }
            }
            else
            {
                var modelStateErrorMessages = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrorMessages.FirstOrDefault()));
            }

            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
        }
        public ActionResult GenericAttributeAdd(GenericAttributeModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel))
            {
                return(AccessDeniedView());
            }

            model.Key   = model.Key.TrimSafe();
            model.Value = model.Value.TrimSafe();

            if (!ModelState.IsValid)
            {
                // display the first model error
                var modelStateErrorMessages = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrorMessages.FirstOrDefault()));
            }

            var storeId = _storeContext.CurrentStore.Id;

            var attr = _genericAttributeService.GetAttribute <string>(model.EntityName, model.EntityId, model.Key, storeId);

            if (attr == null)
            {
                var ga = new GenericAttribute
                {
                    StoreId  = storeId,
                    KeyGroup = model.EntityName,
                    EntityId = model.EntityId,
                    Key      = model.Key,
                    Value    = model.Value
                };
                _genericAttributeService.InsertAttribute(ga);
            }
            else
            {
                return(Content(string.Format(_localizationService.GetResource("Admin.Common.GenericAttributes.NameAlreadyExists"), model.Key)));
            }

            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
        }
Exemple #7
0
        public bool CreateKeys(int customerId)
        {
            if (customerId != 0)
            {
                var    hmac = new HmacAuthentication();
                var    userData = WebApiCachingUserData.Data();
                string key1, key2;

                for (int i = 0; i < 9999; ++i)
                {
                    if (hmac.CreateKeys(out key1, out key2) && !userData.Exists(x => x.PublicKey.IsCaseInsensitiveEqual(key1)))
                    {
                        var apiUser = new WebApiUserCacheData
                        {
                            CustomerId = customerId,
                            PublicKey  = key1,
                            SecretKey  = key2,
                            Enabled    = true
                        };

                        RemoveKeys(customerId);

                        var attribute = new GenericAttribute
                        {
                            EntityId = customerId,
                            KeyGroup = "Customer",
                            Key      = WebApiCachingUserData.Key,
                            Value    = apiUser.ToString()
                        };

                        _genericAttributeService.InsertAttribute(attribute);

                        WebApiCachingUserData.Remove();
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #8
0
 /// <summary>
 /// Inserts an attribute
 /// </summary>
 /// <param name="attribute">attribute</param>
 public void InsertAttribute(GenericAttribute attribute)
 {
     _genericAttributeService.InsertAttribute(attribute);
 }