public override InvoiceTax SaveOrUpdateInvoiceTax(InvoiceTax invoiceTax)
        {
            if (invoiceTax != null && invoiceTax.ID > 0)
                ResetCache(invoiceTax.ID);

            return base.SaveOrUpdateInvoiceTax(invoiceTax);
        }
 public InvoiceTaxWrapper(InvoiceTax invoiceTax)
     : base(invoiceTax.ID)
 {
     Name = invoiceTax.Name;
     Description = invoiceTax.Description;
     Rate = invoiceTax.Rate;
     CreateOn = (ApiDateTime)invoiceTax.CreateOn;
     CreateBy = EmployeeWraper.Get(invoiceTax.CreateBy);
     CanEdit = CRMSecurity.CanEdit(invoiceTax);
     CanDelete = CRMSecurity.CanDelete(invoiceTax);
 }
 public static void DemandDelete(InvoiceTax invoiceTax)
 {
     if (!CanDelete(invoiceTax)) throw CreateSecurityException();
 }
 public static void DemandEdit(InvoiceTax invoiceTax)
 {
     if (!CanEdit(invoiceTax)) throw CreateSecurityException();
 }
 public static void DemandAccessTo(InvoiceTax invoiceTax)
 {
     if (!CanAccessTo(invoiceTax)) throw CreateSecurityException();
 }
 public static List<Guid> GetAccessSubjectGuidsTo(InvoiceTax invoiceTax)
 {
     return GetAccessSubjectGuidsTo((ISecurityObjectId)invoiceTax);
 }
        public InvoiceTaxWrapper UpdateInvoiceTax(
            int id,
            string name,
            string description,
            int rate)
        {
            if (!CRMSecurity.IsAdmin) {
                throw CRMSecurity.CreateSecurityException();
            }

            if (id <= 0 || String.IsNullOrEmpty(name)) throw new ArgumentException();

            if (!DaoFactory.GetInvoiceTaxDao().IsExist(id)) throw new ItemNotFoundException();

            var invoiceTax = new InvoiceTax
                {
                    ID = id,
                    Name = name,
                    Description = description,
                    Rate = rate
                };

            invoiceTax = DaoFactory.GetInvoiceTaxDao().SaveOrUpdateInvoiceTax(invoiceTax);
            MessageService.Send(Request, MessageAction.InvoiceTaxUpdated, invoiceTax.Name);

            return ToInvoiceTaxWrapper(invoiceTax);
        }
 public static void MakePublic(InvoiceTax invoiceTax)
 {
     MakePublic((ISecurityObjectId)invoiceTax);
 }
 public static bool CanEdit(InvoiceTax invoiceTax)
 {
     return IsAdmin;
 }
 public static bool CanDelete(InvoiceTax invoiceTax)
 {
     return CanEdit(invoiceTax) && Global.DaoFactory.GetInvoiceTaxDao().CanDelete(invoiceTax.ID);
 }
        public static bool CanAccessTo(InvoiceTax invoiceTax)
        {
            if (IsAdmin || invoiceTax.CreateBy == SecurityContext.CurrentAccount.ID) return true;

            return false;
        }
 public static void SetAccessTo(InvoiceTax invoiceTax, List<Guid> subjectID)
 {
     SetAccessTo((ISecurityObjectId)invoiceTax, subjectID);
 }
 private InvoiceTaxWrapper ToInvoiceTaxWrapper(InvoiceTax invoiceTax)
 {
     return new InvoiceTaxWrapper(invoiceTax);
 }
        public virtual InvoiceTax SaveOrUpdateInvoiceTax(InvoiceTax invoiceTax)
        {
            _cache.Insert(_invoiceTaxCacheKey, String.Empty);

            using (var db = GetDb())
            {
                return SaveOrUpdateInvoiceTax(invoiceTax, db);
            }
        }
 public static bool IsPrivate(InvoiceTax invoiceTax)
 {
     return IsPrivate((ISecurityObjectId)invoiceTax);
 }
        private InvoiceTax SaveOrUpdateInvoiceTax(InvoiceTax invoiceTax, DbManager db)
        {
            if (String.IsNullOrEmpty(invoiceTax.Name))
                throw new ArgumentException();

            invoiceTax.LastModifedBy = SecurityContext.CurrentAccount.ID;
            invoiceTax.LastModifedOn = DateTime.UtcNow;

            if (db.ExecuteScalar<int>(Query("crm_invoice_tax").SelectCount().Where(Exp.Eq("id", invoiceTax.ID))) == 0)
            {
                invoiceTax.CreateOn = DateTime.UtcNow;
                invoiceTax.CreateBy = SecurityContext.CurrentAccount.ID;

                invoiceTax.ID = db.ExecuteScalar<int>(
                               Insert("crm_invoice_tax")
                              .InColumnValue("id", 0)
                              .InColumnValue("name", invoiceTax.Name)
                              .InColumnValue("description", invoiceTax.Description)
                              .InColumnValue("rate", invoiceTax.Rate)
                              .InColumnValue("create_on", invoiceTax.CreateOn)
                              .InColumnValue("create_by", SecurityContext.CurrentAccount.ID)
                              .InColumnValue("last_modifed_on", invoiceTax.LastModifedOn)
                              .InColumnValue("last_modifed_by", invoiceTax.LastModifedBy)
                              .Identity(1, 0, true));
            }
            else
            {
                var oldInvoiceTax = db.ExecuteList(GetInvoiceTaxSqlQuery(Exp.Eq("id", invoiceTax.ID)))
                    .ConvertAll(ToInvoiceTax)
                    .FirstOrDefault();

                CRMSecurity.DemandEdit(oldInvoiceTax);

                db.ExecuteNonQuery(
                    Update("crm_invoice_tax")
                        .Set("name", invoiceTax.Name)
                        .Set("description", invoiceTax.Description)
                        .Set("rate", invoiceTax.Rate)
                        .Set("last_modifed_on", invoiceTax.LastModifedOn)
                        .Set("last_modifed_by", invoiceTax.LastModifedBy)
                        .Where(Exp.Eq("id", invoiceTax.ID)));
            }

            return invoiceTax;
        }
 public static Dictionary<Guid, string> GetAccessSubjectTo(InvoiceTax invoiceTax)
 {
     return GetAccessSubjectTo((ISecurityObjectId)invoiceTax);
 }
 public static string GetJson(InvoiceTax invoiceTax) {
     return invoiceTax == null ?
             string.Empty :
             JsonConvert.SerializeObject(new
             {
                 id = invoiceTax.ID,
                 name = invoiceTax.Name,
                 rate = invoiceTax.Rate,
                 description = invoiceTax.Description
             });
 }
        public InvoiceTaxWrapper CreateInvoiceTax(
            string name,
            string description,
            int rate)
        {
            if (!CRMSecurity.IsAdmin) {
                throw CRMSecurity.CreateSecurityException();
            }

            if (String.IsNullOrEmpty(name)) throw new ArgumentException();
            if(DaoFactory.GetInvoiceTaxDao().IsExist(name)) throw new ArgumentException();

            var invoiceTax = new InvoiceTax
                {
                    Name = name,
                    Description = description,
                    Rate = rate
                };

            invoiceTax = DaoFactory.GetInvoiceTaxDao().SaveOrUpdateInvoiceTax(invoiceTax);
            MessageService.Send(_context, MessageAction.InvoiceTaxCreated, invoiceTax.Name);

            return ToInvoiceTaxWrapper(invoiceTax);
        }