Exemplo n.º 1
0
        public void DeletePaymentTermTest()
        {
            // Get a test user
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);

            // Create a template
            PaymentTermModel model = createPaymentTerm(testCompany);

            var error = LookupService.InsertOrUpdatePaymentTerm(model, user, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindPaymentTerm(model.Id);
            var test   = LookupService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            LookupService.DeletePaymentTerm(model.Id);

            // And check that is was deleted
            result = db.FindPaymentTerm(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
Exemplo n.º 2
0
        public Error InsertOrUpdatePaymentTerm(PaymentTermModel paymentTerm, UserModel user, string lockGuid)
        {
            var error = validateModel(paymentTerm);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(PaymentTerm).ToString(), paymentTerm.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "LatePaymentChargePercent");
                }
                else
                {
                    PaymentTerm temp = null;
                    if (paymentTerm.Id != 0)
                    {
                        temp = db.FindPaymentTerm(paymentTerm.Id);
                    }
                    if (temp == null)
                    {
                        temp = new PaymentTerm();
                    }

                    Mapper.Map <PaymentTermModel, PaymentTerm>(paymentTerm, temp);

                    db.InsertOrUpdatePaymentTerm(temp);
                    paymentTerm.Id = temp.Id;
                }
            }
            return(error);
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> Update(PaymentTermModel item)
        {
            if (ModelState.IsValid)
            {
                var session     = (Session)ContextOperator.Get(ContextKeys.SESSION_ID);
                var requestInfo = ContextOperator.Get(ContextKeys.REQUEST_INFO_KEY) as Request;

                this._paymentTermService.Update(item, requestInfo, session);
                return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(true, "Success", null))));
            }

            return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.INVALID_REQUEST_PARMS, null))));
        }
Exemplo n.º 4
0
        public ActionResult PostPaymntTerm(PaymentTermModel paymentTermModel)
        {
            HttpResponseMessage response = GlobalVeriables.WebApiClient.PostAsJsonAsync("PostpaymentTerm", paymentTermModel).Result;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Failed", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 5
0
        private Error validateModel(PaymentTermModel model)
        {
            var error = isValidNonRequiredString(getFieldValue(model.TermsOfPaymentId), 4, "TermsOfPaymentId", EvolutionResources.errTextDataRequiredInField);

            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.DiscountDate), 3, "DiscountDate", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.BalanceDueDate), 3, "BalanceDueDate", EvolutionResources.errTextDataRequiredInField);
            }
            return(error);
        }
Exemplo n.º 6
0
        PaymentTermModel createPaymentTerm(CompanyModel company)
        {
            PaymentTermModel model = new PaymentTermModel {
                CompanyId = company.Id,
                LatePaymentChargePercent    = (decimal)10.5,
                EarlyPaymentDiscountPercent = (decimal)5.5,
                TermsOfPaymentId            = "COD",
                TermText           = "Cash on Delivery",
                ImportPaymentIsDue = 20,
                DiscountDays       = 10,
                BalanceDueDays     = 14,
                DiscountDate       = RandomString().Left(3),
                BalanceDueDate     = RandomString().Left(3),
                Enabled            = true
            };

            return(model);
        }
Exemplo n.º 7
0
        public PaymentTermModel FindPaymentTermModel(int id, bool bCreateEmptyIfNotfound = true)
        {
            PaymentTermModel model = null;

            var pt = db.FindPaymentTerm(id);

            if (pt == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new PaymentTermModel();
                }
            }
            else
            {
                model = MapToModel(pt);
            }

            return(model);
        }
        public void Add(PaymentTermModel item, Request request, Session session)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            var paymentTerm = new PaymentTerm
            {
                Id           = item.Id,
                Name         = item.Name,
                Code         = item.Code,
                NumberOfDays = item.NumberOfDays,
                CompanyId    = session.CompanyId,
            };

            this._paymentTermRepository.Add(paymentTerm);
        }
Exemplo n.º 9
0
 public string LockPaymentTerm(PaymentTermModel model)
 {
     return(db.LockRecord(typeof(PaymentTerm).ToString(), model.Id));
 }
Exemplo n.º 10
0
 public static PaymentTerm ToEntity(this PaymentTermModel model, PaymentTerm destination)
 {
     return(AutoMapperConfiguration.Mapper.Map(model, destination));
 }
Exemplo n.º 11
0
 public static PaymentTerm ToEntity(this PaymentTermModel model)
 {
     return(AutoMapperConfiguration.Mapper.Map <PaymentTermModel, PaymentTerm>(model));
 }