Esempio n. 1
0
        public virtual CommonResponse AddTransaction(Entity entity)
        {
            CommonResponse response = new CommonResponse();

            try
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Add(entity);

                        transaction.Commit();
                    }
                    catch (KnownError error)
                    {
                        transaction.Rollback();
                        return(response.Error(error));
                    }
                    catch (CannotCreateBecauseAlreadyExists error)
                    {
                        transaction.Rollback();
                        return(response.Success(error.ExistingEntity));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        // Retrieve the error messages as a list of strings.
                        var errorMessages = ex.EntityValidationErrors
                                            .SelectMany(x => x.ValidationErrors)
                                            .Select(x => x.ErrorMessage);

                        // Join the list to a single string.
                        var fullErrorMessage = string.Join("; ", errorMessages);

                        transaction.Rollback();
                        return(response.Error(fullErrorMessage));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        var originalException = GetOriginalException(ex);
                        return(response.Error("Error " + originalException.Message));
                    }
                }
            }
            catch (KnownError error)
            {
                return(response.Error(error));
            }
            catch (Exception e)
            {
                var originalException = GetOriginalException(e);
                return(response.Error("Error " + originalException.Message));
            }

            return(response.Success(entity));
        }
Esempio n. 2
0
        public virtual CommonResponse GetCatalogs()
        {
            CommonResponse response = new CommonResponse();

            try
            {
                response.Success(LoadCatalogs());
            }
            catch (Exception e)
            {
                return(response.Error("ERROR: " + e.ToString()));
            }
            return(response.Success());
        }
Esempio n. 3
0
        public CommonResponse Checkin(Document document)
        {
            CommonResponse response = new CommonResponse();

            try
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        document.CheckedoutByKey = null;
                        Update(document);

                        _makeRevision(document);

                        transaction.Commit();
                        AdapterOut(document);
                    }
                    catch (KnownError error)
                    {
                        transaction.Rollback();
                        return(response.Error(error));
                    }
                    catch (CannotCreateBecauseAlreadyExists error)
                    {
                        transaction.Rollback();
                        return(response.Success(error.ExistingEntity));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        var originalException = GetOriginalException(ex);
                        return(response.Error("Error " + originalException.Message));
                    }
                }
            }
            catch (KnownError error)
            {
                return(response.Error(error));
            }
            catch (Exception e)
            {
                var originalException = GetOriginalException(e);
                return(response.Error("Error " + originalException.Message));
            }

            return(response.Success(document));
        }
        public CommonResponse Update(cat_TicketType e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketType != "" && e.TicketTypeDescirption != "")
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    cat_TicketType entity = context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id);

                    if (entity != null)
                    {
                        entity.TicketType            = e.TicketType;
                        entity.TicketTypeDescirption = e.TicketTypeDescirption;
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Type does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Type or Description can not be empty.", null);
                return(response);
            }
        }
        public CommonResponse Delete(cat_TicketType e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.id > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    cat_TicketType entity = context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id);
                    if (entity != null)
                    {
                        context.cat_TicketType.Remove(entity);
                        context.SaveChanges();
                        response.Success();
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Type ID can not be find.", null);
                        return(response);
                    }
                }
            }
            response.Error("Ticket Type ID can not be 0.", null);
            return(response);
        }
Esempio n. 6
0
        public virtual CommonResponse GetAvailableFor <ForEntity>(int id) where ForEntity : BaseEntity
        {
            CommonResponse       response = new CommonResponse();
            IEnumerable <Entity> availableEntities;

            try
            {
                //repository.ByUserId = LoggedUser.UserID;

                IRepository <ForEntity> oRepository = new Repository <ForEntity>(context, LoggedUser);
                //oRepository.ByUserId = LoggedUser.UserID;


                ForEntity forEntity = oRepository.GetByID(id);
                if (forEntity == null)
                {
                    throw new Exception("Entity " + forEntity.AAA_EntityName + " not found.");
                }

                IEnumerable <Entity> childrenInForEntity = repository.GetListByParent <ForEntity>(id);

                IEnumerable <Entity> allEntities = repository.GetAll();

                availableEntities = allEntities.Where(e => !childrenInForEntity.Any(o => o.id == e.id));

                AdapterOut(availableEntities.ToArray());
                return(response.Success(availableEntities));
            }
            catch (Exception e)
            {
                return(response.Error("ERROR: " + e.ToString()));
            }
        }
Esempio n. 7
0
        }//by COUNTER

        public CommonResponse Update(Ticket e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketKey != 0 && e.InventoryEventKey != 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    Ticket entity = context.Tickets.FirstOrDefault(r => r.TicketKey == e.TicketKey);

                    if (entity != null)
                    {
                        entity = e;
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Type or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 8
0
        public CommonResponse Delete(cat_UserRole e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.UserRole != "" && e.UserRoleDesc != "")
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    cat_UserRole entity = context.cat_UserRole.FirstOrDefault(r => r.UserRoleKey == e.id);

                    if (entity != null)
                    {
                        entity.UserRole     = e.UserRole;
                        entity.UserRoleDesc = e.UserRoleDesc;
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("User Role does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("User Role or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 9
0
        public CommonResponse ReadbyId(cat_UserRole e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.UserRoleKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    e = context.cat_UserRole.FirstOrDefault(r => r.UserRoleKey == e.id);
                    if (e != null)
                    {
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("User Role ID was not found.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("User Role ID can not be 0.", null);
                return(response);
            }
        }
Esempio n. 10
0
        public CommonResponse Update(FS_ItemMaster e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.ItemNumber_FSKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    FS_ItemMaster entity = context.FS_ItemMaster.FirstOrDefault(r => r.ItemNumber_FSKey == e.ItemNumber_FSKey);

                    if (entity != null)
                    {
                        //entity.UserName = e.UserName;
                        //entity.UserRoleKey = e.UserRoleKey;
                        //entity.Password = e.Password;
                        //context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Item does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Item can not be empty.", null);
                return(response);
            }
        }
Esempio n. 11
0
        public CommonResponse CancelCheckout(int id)
        {
            CommonResponse response = new CommonResponse();

            try
            {
                Document document = repository.GetByID(id);

                if (document.CheckedoutByKey > 0 && LoggedUser.LocalUser.UserKey != document.CheckedoutByKey && LoggedUser.LocalUser.Role != "Administrator")
                {
                    document.CheckedoutBy = context.Set <User>().FirstOrDefault(u => u.UserKey == document.CheckedoutByKey);
                    throw new KnownError(@"Error: Only User who Checked Out can ""Cancel Checked Out"": "
                                         + document.CheckedoutBy?.Value);
                }

                document.CheckedoutByKey = null;
                context.SaveChanges();

                return(response.Success(_GetByID(id)));
            }
            catch (KnownError ke)
            {
                return(response.Error(ke));
            }
            catch (Exception ex)
            {
                return(response.Error(ex.ToString()));
            }
        }
Esempio n. 12
0
        }//by PN

        public CommonResponse Update(TicketCount e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketKey != 0 && e.TagCountKey != 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    TicketCount entity = context.TicketCounts.FirstOrDefault(r => (r.TicketKey == e.TicketKey &&
                                                                                   r.TagCountKey == e.TagCountKey));
                    if (entity != null)
                    {
                        UpdateEntity(ref entity, e);
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket can not be empty.", null);
                return(response);
            }
        }
Esempio n. 13
0
        public CommonResponse Delete(TicketCount e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketKey > 0 && e.TagCountKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    TicketCount entity = context.TicketCounts.FirstOrDefault(r => (r.TicketKey == e.TicketKey &&
                                                                                   r.TagCountKey == e.TagCountKey));
                    if (entity != null)
                    {
                        context.TicketCounts.Remove(entity);
                        context.SaveChanges();
                        response.Success();
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket ID can not be find.", null);
                        return(response);
                    }
                }
            }
            response.Error("Ticket ID can not be 0.", null);
            return(response);
        }
Esempio n. 14
0
        public CommonResponse ReadbyId(TicketCount e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketKey > 0 && e.TagCountKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    e = context.TicketCounts.FirstOrDefault(r => (r.TagCountKey == e.TagCountKey && r.Ticket.cat_TicketType.TicketType == "TicketCount"));
                    if (e != null)
                    {
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Count ID was not found.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Count ID can not be 0.", null);
                return(response);
            }
        }
Esempio n. 15
0
        public CommonResponse Create(TicketCount e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketKey != 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    if (context.TicketCounts.FirstOrDefault(r => (r.id == e.id)) == null)
                    {
                        context.TicketCounts.Add(e);
                        context.SaveChanges();
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Count already exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Id can not be empty.", null);
                return(response);
            }
        }
Esempio n. 16
0
        public CommonResponse GetbyTagNo(Ticket e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            //e.TicketKey = ID;
            if (e.TicketCounter > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    e = context.Tickets.FirstOrDefault(r => (r.TicketCounter == e.TicketCounter && r.InventoryEventKey == e.InventoryEventKey));
                    if (e != null)
                    {
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket ID was not found.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Type ID can not be 0.", null);
                return(response);
            }
        }
Esempio n. 17
0
        public CommonResponse AddCountTicket(Ticket e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketCounter != 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    cat_TicketType _cat_TicketType = context.cat_TicketType.FirstOrDefault(r => r.TicketType == "TicketCount");
                    Ticket         _Ticket         = context.Tickets.FirstOrDefault(r => (r.TicketCounter == e.TicketCounter && r.InventoryEventKey == e.InventoryEventKey));
                    if (_Ticket == null)
                    {
                        _cat_TicketType.Tickets.Add(e);
                        context.SaveChanges();
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Category already exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Category or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 18
0
        public CommonResponse Delete(FS_ItemMaster e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.ItemNumber_FSKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    FS_ItemMaster entity = context.FS_ItemMaster.FirstOrDefault(r => r.ItemNumber_FSKey == e.ItemNumber_FSKey);
                    if (entity != null)
                    {
                        context.FS_ItemMaster.Remove(entity);
                        context.SaveChanges();
                        response.Success();
                        return(response);
                    }
                    else
                    {
                        response.Error("Item ID can not be find.", null);
                        return(response);
                    }
                }
            }
            response.Error("Item ID can not be 0.", null);
            return(response);
        }
Esempio n. 19
0
        public CommonResponse Checkout(int id)
        {
            CommonResponse response = new CommonResponse();

            try
            {
                Document document = repository.GetByID(id);

                if (document.CheckedoutByKey == null)
                {
                    document.CheckedoutByKey = LoggedUser.LocalUser.UserKey;
                    context.SaveChanges();
                }
                else if (document.CheckedoutByKey > 0 && LoggedUser.LocalUser.UserKey != document.CheckedoutByKey)
                {
                    document.CheckedoutBy = context.Set <User>().FirstOrDefault(u => u.UserKey == document.CheckedoutByKey);
                    throw new KnownError("Error: This document is already Checked Out by: " + document.CheckedoutBy?.Value);
                }

                return(response.Success(_GetByID(id)));
            }
            catch (KnownError ke)
            {
                return(response.Error(ke));
            }
            catch (Exception ex)
            {
                return(response.Error(ex.ToString()));
            }
        }
Esempio n. 20
0
        public CommonResponse Update(InventoryEvent e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.InventoryEventKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    InventoryEvent entity = context.InventoryEvents.FirstOrDefault(r => r.InventoryEventKey == e.InventoryEventKey);

                    if (entity != null)
                    {
                        entity.InventoryEventName        = e.InventoryEventName;
                        entity.InventoryEventDescription = e.InventoryEventDescription;
                        entity.Status          = e.Status;
                        entity.TicketCountTags = e.TicketCountTags;
                        entity.MOTags          = e.MOTags;
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Inventory Event does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Inventory Event Name or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 21
0
        public virtual CommonResponse Activate(int id)
        {
            CommonResponse response = new CommonResponse();

            try
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        //repository.ByUserId = LoggedUser.LocalUser.UserKey;
                        repository.Activate(id);

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        return(response.Error("ERROR: " + e.ToString()));
                    }
                }
            }
            catch (Exception e)
            {
                return(response.Error("ERROR: " + e.ToString()));
            }
            return(response.Success(id));
        }
Esempio n. 22
0
        public CommonResponse Delete(InventoryEvent e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.id > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    InventoryEvent entity = context.InventoryEvents.FirstOrDefault(r => r.InventoryEventKey == e.id);
                    if (entity != null)
                    {
                        try
                        {
                            context.InventoryEvents.Remove(entity);
                            context.SaveChanges();
                            response.Success();
                            return(response);
                        }catch (Exception ex)
                        {
                            response.Error(ex.Message, null);
                            return(response);
                        }
                    }
                    else
                    {
                        response.Error("Inventory Event ID can not be find.", null);
                        return(response);
                    }
                }
            }
            response.Error("Inventory Event ID can not be 0.", null);
            return(response);
        }
Esempio n. 23
0
        public CommonResponse Create(cat_UserRole e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.UserRole != "" && e.UserRoleDesc != "")
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    if (context.cat_UserRole.FirstOrDefault(r => r.UserRole == e.UserRole) == null)
                    {
                        context.cat_UserRole.Add(e);
                        context.SaveChanges();
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("User Role already exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("User Role or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 24
0
        public virtual CommonResponse GetByID(int ID)
        {
            CommonResponse response = new CommonResponse();
            List <Entity>  entities = new List <Entity>();

            try
            {
                Entity entity = repository.GetByID(ID);
                if (entity != null)
                {
                    repository.byUserId = loggedUser.UserID;
                    entities.Add(entity);
                    loadNavigationProperties(entities.ToArray());
                    return(response.Success(entity));
                }
                else
                {
                    return(response.Error("Entity not found."));
                }
            }
            catch (Exception e)
            {
                return(response.Error("ERROR: " + e.ToString()));
            }
        }
        public CommonResponse Update(FSTI_Transactions e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.FSTI_Transaction_key > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    FSTI_Transactions entity = context.FSTI_Transactions.FirstOrDefault(r => r.FSTI_Transaction_key == e.FSTI_Transaction_key);

                    if (entity != null)
                    {
                        entity.TransactionStringFields = e.TransactionStringFields;
                        entity.TransactionProcessedYN  = e.TransactionProcessedYN;
                        entity.FSResponse   = e.FSResponse;
                        entity.FSError      = e.FSError;
                        entity.DateStampOut = e.DateStampOut;
                        //entity.Password = e.Password;
                        context.SaveChanges();
                        response.Success(entity, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("FSTI Transaction does not exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("FSTI Transaction key can not be empty.", null);
                return(response);
            }
        }
Esempio n. 26
0
        public CommonResponse Delete(MOTagCount e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.MOTagHeaderKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    MOTagCount entity = context.MOTagCounts.FirstOrDefault(r => r.MOTagCountKey == e.MOTagCountKey);
                    if (entity != null)
                    {
                        context.MOTagCounts.Remove(entity);
                        context.SaveChanges();
                        response.Success();
                        return(response);
                    }
                    else
                    {
                        response.Error("MO Tag Line ID can not be find.", null);
                        return(response);
                    }
                }
            }
            response.Error("MO Tag Line ID can not be 0.", null);
            return(response);
        }
Esempio n. 27
0
        public CommonResponse Create(InventoryEvent e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.InventoryEventName != "" && e.InventoryEventName != "")
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    if (context.InventoryEvents.FirstOrDefault(r => r.InventoryEventName == e.InventoryEventName) == null)
                    {
                        context.InventoryEvents.Add(e);
                        context.SaveChanges();
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Inventory Event already exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Inventory Event Name or Description can not be empty.", null);
                return(response);
            }
        }
Esempio n. 28
0
        public CommonResponse ReadbyId(int ID)
        {
            CommonResponse response = new Reusable.CommonResponse();
            Ticket         e        = new Ticket {
                TicketKey = ID
            };

            //e.TicketKey = ID;
            if (e.TicketKey > 0)
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    e = context.Tickets.FirstOrDefault(r => r.TicketKey == e.TicketKey);
                    if (e != null)
                    {
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket ID was not found.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Type ID can not be 0.", null);
                return(response);
            }
        }
Esempio n. 29
0
        public virtual CommonResponse GetSingleWhere(params Expression <Func <Entity, bool> >[] wheres)
        {
            CommonResponse response       = new CommonResponse();
            FilterResponse filterResponse = new FilterResponse();

            Entity entity;

            try
            {
                //repository.ByUserId = LoggedUser.UserID;

                entity = repository.GetSingle(null, wheres);
                if (entity != null)
                {
                    OnGetSingle(entity);
                    AdapterOut(entity);
                }
                return(response.Success(entity));
            }
            catch (Exception e)
            {
                var originalException = GetOriginalException(e);
                return(response.Error("Error " + originalException.Message));
            }
        }
Esempio n. 30
0
        public CommonResponse Create(cat_TicketType e)
        {
            CommonResponse response = new Reusable.CommonResponse();

            if (e.TicketType != "" && e.TicketTypeDescirption != "")
            {
                using (CAPA_INVContext context = new CAPA_INVContext())
                {
                    if (context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id) == null)
                    {
                        context.cat_TicketType.Add(e);
                        context.SaveChanges();
                        response.Success(e, "OK");
                        return(response);
                    }
                    else
                    {
                        response.Error("Ticket Category already exist.", null);
                        return(response);
                    }
                }
            }
            else
            {
                response.Error("Ticket Category or Description can not be empty.", null);
                return(response);
            }
        }