/// <summary>
        /// Save or update records for the table
        /// </summary>
        /// <param name="listDataUserApplication">List of data to store UserApplication.</param>
        /// <returns>The result of processing the list.</returns>
        /// <author>Mauricio Suárez.</author>
        public List <UserApplicationDto> SaveUserApplication(List <UserApplicationDto> listUserApplicationDto)
        {
            List <UserApplication> listSaleResult = new List <UserApplication>();

            using (SecurityManagmentEntities context = new SecurityManagmentEntities())
            {
                ObjectContext objectContext     = ((IObjectContextAdapter)context).ObjectContext;
                ObjectSet <UserApplication> set = objectContext.CreateObjectSet <UserApplication>();
                string[] entitySaleKeys         = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).ToArray();

                bool[] resultValidateInsertOrUpdate = ConditionalQuery.ValidatePrimaryKeyValueInDto(listUserApplicationDto, entitySaleKeys);

                int resultValidateInsertOrUpdateCount = resultValidateInsertOrUpdate.Count();

                int i = 0;
                foreach (UserApplicationDto dtoSale in listUserApplicationDto)
                {
                    UserApplication entitySale = Mapper.Map <UserApplicationDto, UserApplication>(dtoSale);

                    if (resultValidateInsertOrUpdateCount > 0)
                    {
                        if (resultValidateInsertOrUpdate[i])
                        {
                            context.UserApplication.Attach(entitySale);
                            context.Entry(entitySale).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            context.UserApplication.Add(entitySale);
                        }
                    }
                    else
                    {
                        context.UserApplication.Add(entitySale);
                    }

                    listSaleResult.Add(entitySale);
                    i++;
                }

                context.SaveChanges();
            }

            listUserApplicationDto = null;
            return(listSaleResult.Select(Mapper.Map <UserApplication, UserApplicationDto>).ToList());
        }
Beispiel #2
0
        /// <summary>
        /// Save or update records for the table
        /// </summary>
        /// <param name="listDataApplication">List of data to store Application.</param>
        /// <returns>The result of processing the list.</returns>
        /// <author>Mauricio Suárez.</author>
        public bool SaveApplication(List <ApplicationDto> listApplicationDto)
        {
            using (SecurityManagmentEntities context = new SecurityManagmentEntities())
            {
                ObjectContext           objectContext = ((IObjectContextAdapter)context).ObjectContext;
                ObjectSet <Application> set           = objectContext.CreateObjectSet <Application>();
                string[] entityOrderDetailKeys        = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).ToArray();

                bool[] resultValidateInsertOrUpdate = ConditionalQuery.ValidatePrimaryKeyValueInDto(listApplicationDto, entityOrderDetailKeys);

                int resultValidateInsertOrUpdateCount = resultValidateInsertOrUpdate.Count();

                int i = 0;
                foreach (ApplicationDto dtoApplication in listApplicationDto)
                {
                    if (resultValidateInsertOrUpdateCount > 0)
                    {
                        Application entityOrderDetail = null;
                        if (resultValidateInsertOrUpdate[i])
                        {
                            entityOrderDetail = Mapper.Map <ApplicationDto, Application>(dtoApplication);
                            context.Entry(entityOrderDetail).State = System.Data.Entity.EntityState.Modified;
                            context.Application.Attach(entityOrderDetail);
                        }
                        else
                        {
                            context.Application.Add(Mapper.Map <ApplicationDto, Application>(dtoApplication));
                        }
                    }
                    else
                    {
                        context.Application.Add(Mapper.Map <ApplicationDto, Application>(dtoApplication));
                    }
                    i++;
                }

                context.SaveChanges();
            }

            return(true);
        }