public void create(Sale sale)
        {
            bool verification = true;

            try
            {
                string total    = sale.Total.ToString();
                double totalAux = 0;

                if (string.IsNullOrWhiteSpace(total))
                {
                    throw new Exception("A venda necessita de um valor total valido!!!");
                }

                totalAux = Convert.ToDouble(sale.Total);

                verification = totalAux > 0 && totalAux <= 999999999;
                if (!verification)
                {
                    throw new Exception("O número total é maior que o esperado!!!");
                }

                string date = sale.Data.ToString();
                if (string.IsNullOrWhiteSpace(date))
                {
                    throw new Exception("Informe por favor uma data válida!!!");
                }

                date         = sale.Data.Trim();
                verification = date.Length == 10;
                if (!verification)
                {
                    throw new Exception("O tamanho da data deve ter 10 caracteres!!!");
                }

                saleDao.Create(sale);
                sale.State = 99;
                return;
            }
            catch (Exception erro)
            {
                Message.MessageError(erro.Message);
            }
        }
Exemple #2
0
        // Ìí¼Ó
        public ContentResult Create(Sale sale, List <SaleItem> items)
        {
            string result = "{success:false,Id:0}";
            User   user   = (User)Session["user"];

            sale.SaleItem.AddRange(items);
            sale.AddId     = user.Id;
            sale.AddName   = user.Name;
            sale.DateAdded = DateTime.Now;
            sale.Status    = "´ý³ö¿â";
            int id = dao.Create(sale);

            if (id > 0)
            {
                result = "{success:true,Id:" + id + "}";
            }
            return(new ContentResult
            {
                Content = result
            });
        }