Exemplo n.º 1
0
        //Adddate CIMS
        /// <summary>
        ///Phongtv
        /// AddCimsValue
        /// </summary>
        /// <param name="lstCustomer"></param>
        /// <returns></returns>
        public object AddCimsValue(List <TblCimsattributeValue> lstCustomer, string username)
        {
            var rowIdentify = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");

            const string module = "CIMS";

            try
            {
                List <object> lstErrs = new List <object>();
                List <TblCimsattributeValue> lstAttributes = new List <TblCimsattributeValue>();

                TblCimsattributeValue CimsAdd1 = new TblCimsattributeValue();

                CimsAdd1.AttributeCode  = "ATTRIBUTE1";
                CimsAdd1.AttributeValue = username;
                CimsAdd1.Module         = module;
                CimsAdd1.IsDelete       = false;
                CimsAdd1.RecordId       = rowIdentify;
                CimsAdd1.CreatedDate    = DateTime.Now;
                CimsAdd1.UpdatedBy      = username;
                lstAttributes.Add(CimsAdd1);

                TblCimsattributeValue CimsAdd2 = new TblCimsattributeValue();
                CimsAdd2.AttributeCode  = "ATTRIBUTE2";
                CimsAdd2.AttributeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                CimsAdd2.Module         = module;
                CimsAdd2.IsDelete       = false;
                CimsAdd2.RecordId       = rowIdentify;
                CimsAdd2.CreatedDate    = DateTime.Now;
                CimsAdd2.UpdatedBy      = username;
                lstAttributes.Add(CimsAdd2);



                for (int i = 0; i < (lstCustomer.Count); i++)
                {
                    if (lstCustomer[i].AttributeCode != "ATTRIBUTE1" && lstCustomer[i].AttributeCode != "ATTRIBUTE2")
                    {
                        var tblVocattributesIsRequired = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsRequired == true).FirstOrDefault();
                        if (tblVocattributesIsRequired != null)
                        {
                            if (lstCustomer[i].AttributeValue.Length > 0)
                            {
                                TblVocattributes tblVocattributesIsDuplicate = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsDuplicate == true
                                                                                                         ).FirstOrDefault();
                                if (tblVocattributesIsDuplicate != null)
                                {
                                    TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == lstCustomer[i].AttributeCode && b.AttributeValue.ToString().ToLower() == lstCustomer[i].AttributeValue.ToLower()).FirstOrDefault();
                                    if (cimsValue == null)
                                    {
                                        TblVocattributes attcheck = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsReuse == true).FirstOrDefault();

                                        if (attcheck == null)
                                        {
                                            TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                            CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                            CimsAdd.AttributeValue = lstCustomer[i].AttributeValue;
                                            CimsAdd.Module         = module;
                                            CimsAdd.IsDelete       = false;
                                            CimsAdd.RecordId       = rowIdentify;
                                            CimsAdd.CreatedDate    = DateTime.Now;
                                            CimsAdd.UpdatedBy      = username;
                                            lstAttributes.Add(CimsAdd);
                                        }
                                        else
                                        {
                                            string currDate = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                                            TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                            CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                            CimsAdd.AttributeValue = "CUS." + currDate;
                                            CimsAdd.Module         = module;
                                            CimsAdd.IsDelete       = false;
                                            CimsAdd.RecordId       = rowIdentify;
                                            CimsAdd.CreatedDate    = DateTime.Now;
                                            CimsAdd.UpdatedBy      = username;
                                            lstAttributes.Add(CimsAdd);
                                        }
                                    }
                                    else
                                    {
                                        lstErrs.Add(new
                                        {
                                            field   = tblVocattributesIsDuplicate.AttributeCode,
                                            name    = tblVocattributesIsDuplicate.AttributeLabel,
                                            message = "NotDuplicate"
                                        });
                                    }
                                }
                                else
                                {
                                    TblVocattributes attcheck = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsReuse == true).FirstOrDefault();

                                    if (attcheck == null)
                                    {
                                        TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                        CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                        CimsAdd.AttributeValue = lstCustomer[i].AttributeValue;
                                        CimsAdd.Module         = module;
                                        CimsAdd.IsDelete       = false;
                                        CimsAdd.RecordId       = rowIdentify;
                                        CimsAdd.CreatedDate    = DateTime.Now;
                                        CimsAdd.UpdatedBy      = username;
                                        lstAttributes.Add(CimsAdd);
                                    }
                                    else
                                    {
                                        string currDate = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                                        TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                        CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                        CimsAdd.AttributeValue = "CUS." + currDate;
                                        CimsAdd.Module         = module;
                                        CimsAdd.IsDelete       = false;
                                        CimsAdd.RecordId       = rowIdentify;
                                        CimsAdd.CreatedDate    = DateTime.Now;
                                        CimsAdd.UpdatedBy      = username;
                                        lstAttributes.Add(CimsAdd);
                                    }
                                }
                            }
                            else
                            {
                                lstErrs.Add(new
                                {
                                    field   = tblVocattributesIsRequired.AttributeCode,
                                    name    = tblVocattributesIsRequired.AttributeLabel,
                                    message = "NotNull"
                                });
                            }
                        }
                        else
                        {
                            TblVocattributes tblVocattributesIsDuplicate = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsDuplicate == true
                                                                                                     ).FirstOrDefault();
                            if (tblVocattributesIsDuplicate != null)
                            {
                                TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == tblVocattributesIsDuplicate.AttributeCode && b.AttributeValue.ToString().ToLower() == lstCustomer[i].AttributeValue.ToLower()).FirstOrDefault();
                                if (cimsValue == null)
                                {
                                    TblVocattributes attcheck = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsReuse == true).FirstOrDefault();

                                    if (attcheck == null)
                                    {
                                        TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                        CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                        CimsAdd.AttributeValue = lstCustomer[i].AttributeValue;
                                        CimsAdd.Module         = module;
                                        CimsAdd.IsDelete       = false;
                                        CimsAdd.RecordId       = rowIdentify;
                                        CimsAdd.CreatedDate    = DateTime.Now;
                                        CimsAdd.UpdatedBy      = username;
                                        lstAttributes.Add(CimsAdd);
                                    }
                                    else
                                    {
                                        string currDate = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                                        TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                        CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                        CimsAdd.AttributeValue = "CUS." + currDate;
                                        CimsAdd.Module         = module;
                                        CimsAdd.IsDelete       = false;
                                        CimsAdd.RecordId       = rowIdentify;
                                        CimsAdd.CreatedDate    = DateTime.Now;
                                        CimsAdd.UpdatedBy      = username;
                                        lstAttributes.Add(CimsAdd);
                                    }
                                }
                                else
                                {
                                    lstErrs.Add(new
                                    {
                                        field   = tblVocattributesIsDuplicate.AttributeCode,
                                        name    = tblVocattributesIsDuplicate.AttributeLabel,
                                        message = "NotDuplicate"
                                    });
                                }
                            }
                            else
                            {
                                TblVocattributes attcheck = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsReuse == true).FirstOrDefault();

                                if (attcheck == null)
                                {
                                    TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                    CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                    CimsAdd.AttributeValue = lstCustomer[i].AttributeValue;
                                    CimsAdd.Module         = module;
                                    CimsAdd.IsDelete       = false;
                                    CimsAdd.RecordId       = rowIdentify;
                                    CimsAdd.CreatedDate    = DateTime.Now;
                                    CimsAdd.UpdatedBy      = username;
                                    lstAttributes.Add(CimsAdd);
                                }
                                else
                                {
                                    string currDate = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                                    TblCimsattributeValue CimsAdd = new TblCimsattributeValue();
                                    CimsAdd.AttributeCode  = lstCustomer[i].AttributeCode;
                                    CimsAdd.AttributeValue = "CUS." + currDate;
                                    CimsAdd.Module         = module;
                                    CimsAdd.IsDelete       = false;
                                    CimsAdd.RecordId       = rowIdentify;
                                    CimsAdd.CreatedDate    = DateTime.Now;
                                    CimsAdd.UpdatedBy      = username;
                                    lstAttributes.Add(CimsAdd);
                                }
                            }
                        }
                    }
                }

                // list
                if (lstErrs.Count > 0)
                {
                    return(lstErrs);
                }
                var lst = db.TblVocattributes.Where(v => v.ModuleParent == "CIMS" &&
                                                    v.IsDelete == false && lstCustomer.Where(x => x.AttributeCode == v.AttributeCode).Count() == 0 && v.AttributeCode != "ATTRIBUTE1" && v.AttributeCode != "ATTRIBUTE2").
                          Select(x => new TblCimsattributeValue()
                {
                    AttributeCode  = x.AttributeCode,
                    Module         = module,
                    AttributeValue = "",
                    IsDelete       = false,
                    RecordId       = rowIdentify,
                    CreatedDate    = DateTime.Now,
                    UpdatedBy      = username
                });
                lstAttributes.AddRange(lst);
                db.TblCimsattributeValue.AddRange(lstAttributes);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        //Edit CIMS
        /// <summary>
        ///
        /// </summary>
        /// <param name="lstCustomer"></param>
        /// <param name="rowIdentify"></param>
        /// <returns></returns>
        public object EditCimsValue(List <TblCimsattributeValue> lstCustomer, string rowIdentify, string username)
        {
            TblCimsattributeValue AttributesValue = db.TblCimsattributeValue.Where(a => a.RecordId == rowIdentify).FirstOrDefault();

            if (AttributesValue != null)
            {
                List <object> lstErrs = new List <object>();
                List <TblCimsattributeValue> lstAttributes = new List <TblCimsattributeValue>();

                for (int i = 0; i < lstCustomer.Count; i++)
                {
                    TblVocattributes tblVocattributesIsRequired = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsRequired == true).FirstOrDefault();
                    if (tblVocattributesIsRequired != null)
                    {
                        if (lstCustomer[i].AttributeValue.Length > 0)
                        {
                            TblVocattributes tblVocattributesIsDuplicate = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsDuplicate == true
                                                                                                     ).FirstOrDefault();
                            if (tblVocattributesIsDuplicate != null)
                            {
                                TblCimsattributeValue cimsCheck = db.TblCimsattributeValue.Where(b => b.AttributeCode.TrimEnd() == lstCustomer[i].AttributeCode && b.AttributeValue.ToString().ToLower() == lstCustomer[i].AttributeValue.ToLower() &&
                                                                                                 b.RecordId != rowIdentify).FirstOrDefault();
                                if (cimsCheck == null)
                                {
                                    TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == lstCustomer[i].AttributeCode &&
                                                                                                     b.RecordId == rowIdentify).FirstOrDefault();
                                    cimsValue.AttributeCode   = lstCustomer[i].AttributeCode;
                                    cimsValue.AttributeValue  = lstCustomer[i].AttributeValue;
                                    cimsValue.UpdatedBy       = username;
                                    cimsValue.UpdatedDate     = DateTime.Now;
                                    db.Entry(cimsValue).State = EntityState.Modified;
                                    db.SaveChanges();
                                }
                                else
                                {
                                    lstErrs.Add(new
                                    {
                                        field   = tblVocattributesIsDuplicate.AttributeCode,
                                        name    = tblVocattributesIsDuplicate.AttributeLabel,
                                        message = "NotDuplicate"
                                    });
                                }
                            }
                            else
                            {
                                TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == lstCustomer[i].AttributeCode &&
                                                                                                 b.RecordId == rowIdentify).FirstOrDefault();
                                cimsValue.AttributeCode   = lstCustomer[i].AttributeCode;
                                cimsValue.AttributeValue  = lstCustomer[i].AttributeValue;
                                cimsValue.UpdatedBy       = username;
                                cimsValue.UpdatedDate     = DateTime.Now;
                                db.Entry(cimsValue).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            lstErrs.Add(new
                            {
                                field   = tblVocattributesIsRequired.AttributeCode,
                                name    = tblVocattributesIsRequired.AttributeLabel,
                                message = "NotNull"
                            });
                        }
                    }
                    else
                    {
                        TblVocattributes tblVocattributesIsDuplicate = db.TblVocattributes.Where(a => a.AttributeCode == lstCustomer[i].AttributeCode && a.IsDuplicate == true
                                                                                                 ).FirstOrDefault();
                        if (tblVocattributesIsDuplicate != null)
                        {
                            TblCimsattributeValue cimsCheck = db.TblCimsattributeValue.Where(b => b.AttributeCode.TrimEnd() == lstCustomer[i].AttributeCode && b.AttributeValue.ToString().ToLower() == lstCustomer[i].AttributeValue.ToLower() &&
                                                                                             b.RecordId != rowIdentify).FirstOrDefault();
                            if (cimsCheck == null)
                            {
                                TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == lstCustomer[i].AttributeCode &&
                                                                                                 b.RecordId == rowIdentify).FirstOrDefault();
                                cimsValue.AttributeCode   = lstCustomer[i].AttributeCode;
                                cimsValue.AttributeValue  = lstCustomer[i].AttributeValue;
                                cimsValue.UpdatedBy       = username;
                                cimsValue.UpdatedDate     = DateTime.Now;
                                db.Entry(cimsValue).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                            else
                            {
                                lstErrs.Add(new
                                {
                                    field   = tblVocattributesIsDuplicate.AttributeCode,
                                    name    = tblVocattributesIsDuplicate.AttributeLabel,
                                    message = "NotDuplicate"
                                });
                            }
                        }
                        else
                        {
                            TblCimsattributeValue cimsValue = db.TblCimsattributeValue.Where(b => b.AttributeCode == lstCustomer[i].AttributeCode &&
                                                                                             b.RecordId == rowIdentify).FirstOrDefault();
                            bool isNew = cimsValue == null;
                            if (isNew)
                            { // Add by daibh
                                cimsValue             = new TblCimsattributeValue();
                                cimsValue.Module      = "CIMS";
                                cimsValue.IsDelete    = false;
                                cimsValue.RecordId    = rowIdentify;
                                cimsValue.CreatedDate = DateTime.Now;
                                cimsValue.UpdatedBy   = username;
                            }

                            cimsValue.AttributeCode  = lstCustomer[i].AttributeCode;
                            cimsValue.AttributeValue = lstCustomer[i].AttributeValue;
                            cimsValue.UpdatedDate    = DateTime.Now;
                            cimsValue.UpdatedBy      = username;

                            if (isNew)
                            { // Add by daibh
                                db.TblCimsattributeValue.Add(cimsValue);
                            }
                            else
                            {
                                db.Entry(cimsValue).State = EntityState.Modified;
                            }
                            db.SaveChanges();
                        }
                    }
                }

                // list
                if (lstErrs.Count > 0)
                {
                    return(lstErrs);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }