public TaskCampaign SaveTaskRegister(string inputTask, Guid idAccount)
        {
            TaskCampaign result;
            var          taskModelView = JSonConvertUtil.Deserialize <TaskRegisterModelView>(inputTask);
            var          task          = new TaskCampaign()
            {
                IdAccount    = idAccount,
                IdBranch     = taskModelView.IdBranch,
                IdCampaign   = taskModelView.IdCampaign,
                IdMerchant   = taskModelView.IdMerchant,
                IdStatusTask = taskModelView.IdStatusTask,
                Description  = taskModelView.Description,
                StartDate    = taskModelView.StartDate,
                Campaign     = null,
                Branch       = null
            };

            if (taskModelView.IdStatusTask == Guid.Empty)
            {
                var status = _statusTaskBusiness.GeStatusTaskByName(CTask.StatusPending);
                task.IdStatusTask = status.Id;
            }

            using (var transaccion = Context.Database.BeginTransaction())
            {
                try
                {
                    if (string.IsNullOrEmpty(task.Code))
                    {
                        var nextSequence = _sequenceBusiness.NextSequence(CTask.SequenceCode,
                                                                          idAccount);

                        task.Code = nextSequence.ToString();
                    }

                    var stateRegister = EntityState.Added;

                    if (Guid.Empty != task.Id)
                    {
                        stateRegister = EntityState.Modified;
                    }

                    Context.TaskCampaigns.Add(task);

                    Context.Entry(task).State = stateRegister;

                    //graba cambios en COntexto
                    Context.SaveChanges();
                    transaccion.Commit();
                    result = GetTaskByIdForRegisterPage(task.Id, idAccount);
                }
                catch
                {
                    transaccion.Rollback();
                    result = null;
                }
            }

            return(result);
        }
Пример #2
0
        public Service SaveService(Service tempService, Guid idAccount)
        {
            if (string.IsNullOrEmpty(tempService.Code))
            {
                var nextSequence = _sequenceBusiness.NextSequence(CService.SequenceCode, idAccount);

                var internalCode = nextSequence.Initial + "-" + nextSequence.SequenceCurrent;
                tempService.Code = internalCode;
            }

            tempService.IdAccount      = idAccount;
            tempService.StatusRegister = CStatusRegister.Active;

            _serviceDao.InsertOrUpdate(tempService);

            return(tempService);
        }
Пример #3
0
        /// <summary>
        /// Guardar Productos
        /// </summary>
        /// <param name="product"></param>
        /// <param name="idAccount"></param>
        public Product SaveProduct(Product product, Guid idAccount)
        {
            product.ProductCategory = null;
            product.Account         = null;
            product.Customer        = null;

            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    if (string.IsNullOrEmpty(product.Code))
                    {
                        var nextSequence = _sequenceBusiness.NextSequence(CProduct.SequenceCode, idAccount);

                        product.Code = nextSequence.ToString();
                    }

                    product.IdAccount      = idAccount;
                    product.StatusRegister = CStatusRegister.Active;

                    var stateRegsiter = EntityState.Added;

                    if (Guid.Empty != product.Id)
                    {
                        stateRegsiter = EntityState.Modified;
                    }

                    Context.Products.Add(product);
                    Context.Entry(product).State = stateRegsiter;

                    Context.SaveChanges();

                    transaction.Commit();

                    product = _productDao.GetProductById(product.Id);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    product = null;
                }
            }

            return(product);
        }
Пример #4
0
        public Campaign SaveCampaign(Campaign campaign, List <ListCampaignServicesViewModel> itemServices, Guid idAccount)
        {
            campaign.Supervisor = null;
            campaign.Customer   = null;
            campaign.CampaignServices.Clear();
            campaign.IdAccount      = idAccount;
            campaign.StatusRegister = CStatusRegister.Active;

            foreach (var servicios in itemServices)
            {
                campaign.CampaignServices.Add(new CampaignServices()
                {
                    IdService      = servicios.IdService,
                    StatusRegister = CStatusRegister.Active,
                    IdAccount      = idAccount
                });
            }

            var stateRegister = EntityState.Added;

            using (var transaccion = Context.Database.BeginTransaction())
            {
                try
                {
                    if (string.IsNullOrEmpty(campaign.Code))
                    {
                        var nextSequence = _sequenceBusiness.NextSequence(CCampaign.SequenceCode, idAccount);
                        var cust         = _customerDao.GetCustomerById(campaign.IdCustomer, idAccount);

                        campaign.Code  = nextSequence.ToString();
                        campaign.Name  = nextSequence.SequenceCurrent.ToString();
                        campaign.Name += "-" + cust.Abbreviation.Trim() + "-" +
                                         campaign.CreationDate.ToString("MMMM", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        //elimino los CampaignServices
                        Context.CampaignsServices.RemoveRange(Context.CampaignsServices.Where(cs => cs.IdCampaign == campaign.Id));
                        Context.SaveChanges();
                        campaign.CampaignServices.Clear();
                    }

                    if (Guid.Empty != campaign.Id)
                    {
                        stateRegister = EntityState.Modified;
                    }

                    Context.Campaigns.Add(campaign);
                    Context.Entry(campaign).State = stateRegister;
                    Context.SaveChanges();
                    transaccion.Commit();
                }
                catch (Exception)
                {
                    transaccion.Rollback();
                    campaign = null;
                }
            }

            return(campaign);
        }
Пример #5
0
        public Branch SaveBranch(Branch branch, Guid idAccount)
        {
            branch.PersonOwner.IdAccount          = idAccount;
            branch.PersonAdministration.IdAccount = idAccount;
            branch.StatusRegister = CStatusRegister.Active;
            branch.IdAccount      = idAccount;
            branch.Country        = null;
            branch.Province       = null;
            branch.District       = null;
            branch.Parish         = null;
            branch.Sector         = null;

            if (branch.PersonAdministration.Id != Guid.Empty)
            {
                branch.PersonAdministration = null;
            }
            if (branch.PersonOwner.Id != Guid.Empty)
            {
                branch.PersonOwner = null;
            }

            branch.IdAccount      = idAccount;
            branch.StatusRegister = CStatusRegister.Active;

            var stateRegister = Guid.Empty == branch.Id ? EntityState.Added : EntityState.Modified;

            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    //Cuando el dueño es administrador y es un nuevo dueño
                    if (branch.IsAdministratorOwner == CBranch.Yes &&
                        (branch.IdPersonAdministrator == Guid.Empty || null == branch.IdPersonAdministrator))
                    {
                        var personOwner = branch.PersonOwner;
                        var secuencia   = _sequenceBusiness.NextSequence(CPerson.SequenceCode, idAccount);

                        if (personOwner != null)
                        {
                            personOwner.Code = secuencia.ToString();
                            Context.Persons.Add(personOwner);
                            Context.SaveChanges();
                            branch.PersonOwner          = null;
                            branch.PersonAdministration = null;

                            branch.IdPersonAdministrator = personOwner.Id;
                            branch.IdPersonOwner         = personOwner.Id;
                        }
                        else
                        {
                            throw new ExceptionMardis("Error al insertar Persona");
                        }
                    }
                    Sequence nextSequence;
                    if (string.IsNullOrEmpty(branch.Code))
                    {
                        nextSequence = _sequenceBusiness.NextSequence(CBranch.SequenceCode, idAccount);
                        var returnCode = nextSequence.Initial + "-" + nextSequence.SequenceCurrent;

                        branch.Code = returnCode;
                    }
                    else
                    {
                        //Elimino los Branchustomers
                        _branchDao.DeleteBranchCustomers(branch.Id, idAccount);
                    }

                    if (branch.IdPersonAdministrator == Guid.Empty)
                    {
                        nextSequence = _sequenceBusiness.NextSequence(CPerson.SequenceCode, idAccount);
                        if (branch.PersonAdministration != null)
                        {
                            branch.PersonAdministration.Code = nextSequence.ToString();
                        }
                    }

                    if (branch.IdPersonOwner == Guid.Empty)
                    {
                        nextSequence = _sequenceBusiness.NextSequence(CPerson.SequenceCode, idAccount);
                        if (branch.PersonOwner != null)
                        {
                            branch.PersonOwner.Code = nextSequence.ToString();
                        }
                    }

                    Context.Branches.Add(branch);

                    Context.Entry(branch).State = stateRegister;

                    Context.SaveChanges();

                    transaction.Commit();

                    branch = GetOne(branch.Id, idAccount);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    branch = null;
                }
            }

            return(branch);
        }