Example #1
0
        private bool UpdateDm(string code, string name, string remark, bool status)
        {
            bool res = false;

            try
            {
                MasterAssetModel asset_Model_Master = _context.MasterAssetModel.FirstOrDefault(m => m.Code.Equals(code));
                if (asset_Model_Master != null)
                {
                    asset_Model_Master.Name             = name;
                    asset_Model_Master.Remark           = remark;
                    asset_Model_Master.Status           = status;
                    asset_Model_Master.ModifiedDatetime = DateTime.UtcNow;
                    asset_Model_Master.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Modifiedby");
                    _context.SaveChanges();
                    res = true;
                }
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }
Example #2
0
        private bool CreateDm(string code, string name, string remark, bool status)
        {
            bool             res = false;
            MasterAssetModel asset_Model_Master = new MasterAssetModel();

            try
            {
                asset_Model_Master.Code            = code;
                asset_Model_Master.Name            = name;
                asset_Model_Master.Remark          = remark;
                asset_Model_Master.CompanyId       = 123;
                asset_Model_Master.IsUsed          = true;
                asset_Model_Master.Status          = status;
                asset_Model_Master.CreatedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                asset_Model_Master.CreatedDatetime = DateTime.UtcNow;
                _context.Add(asset_Model_Master);
                _context.SaveChanges();
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }
Example #3
0
        public async Task <IActionResult> Create([FromForm] MasterAssetModel asset_Model_Master)
        {
            if (ModelState.IsValid)
            {
                bool isCodeExist = _context.MasterAssetModel.Any(m => m.Code.Equals(asset_Model_Master.Code));
                if (isCodeExist)
                {
                    ModelState.AddModelError("Code", "Code Already Exists!");
                    return(View(asset_Model_Master));
                    //return RedirectToAction(nameof(Create), new { error = "Code exists" });
                }
                string newJson = JsonConvert.SerializeObject(asset_Model_Master);

                asset_Model_Master.CompanyId       = 123;
                asset_Model_Master.IsUsed          = true;
                asset_Model_Master.Status          = asset_Model_Master.Status;
                asset_Model_Master.CreatedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                asset_Model_Master.CreatedDatetime = DateTime.UtcNow;
                _context.Add(asset_Model_Master);
                await _context.SaveChangesAsync();

                AuditService.InsertActionLog(asset_Model_Master.CompanyId, asset_Model_Master.CreatedBy, "Create", "Master Asset Model", null, newJson);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(asset_Model_Master));
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, [FromForm] MasterAssetModel asset_Model_Master)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool isCodeExist = _context.MasterAssetModel.Any(m => m.Code.Equals(asset_Model_Master.Code) && !m.Id.Equals(id));
                    if (isCodeExist)
                    {
                        ModelState.AddModelError("Code", "Code Already Exists!");
                        return(View(asset_Model_Master));
                        //return RedirectToAction(nameof(Index), new { error = "Code exists" });
                    }

                    MasterAssetModel db_asset_Model_Master = _context.MasterAssetModel.FirstOrDefault(m => m.Id.Equals(asset_Model_Master.Id));
                    if (asset_Model_Master == null || id != asset_Model_Master.Id)
                    {
                        return(NotFound());
                    }

                    OldData oldData = new OldData();
                    oldData.Code   = db_asset_Model_Master.Code;
                    oldData.Name   = db_asset_Model_Master.Name;
                    oldData.Remark = db_asset_Model_Master.Remark;
                    oldData.Status = db_asset_Model_Master.Status;

                    string oldJson = JsonConvert.SerializeObject(oldData);
                    string newJson = JsonConvert.SerializeObject(asset_Model_Master);

                    db_asset_Model_Master.Code             = asset_Model_Master.Code;
                    db_asset_Model_Master.Name             = asset_Model_Master.Name;
                    db_asset_Model_Master.Status           = asset_Model_Master.Status;
                    db_asset_Model_Master.Remark           = asset_Model_Master.Remark;
                    db_asset_Model_Master.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                    db_asset_Model_Master.ModifiedDatetime = DateTime.UtcNow;

                    _context.Update(db_asset_Model_Master);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Asset_Model_MasterExists(asset_Model_Master.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(asset_Model_Master));
        }
Example #5
0
        public async Task <FileResult> Export()
        {
            string[] names = typeof(MasterAssetModel).GetProperties().Select(property => property.Name).ToArray();

            string[] columnNames = new string[] { "Id", "OldData", "NewData", "ActionModule", "ActionType", "CompanyId", "ObjectId", "CreatedOnUtc", "UserId" };

            MasterAssetModel entities = new MasterAssetModel();

            var auditTrails = await _context.AuditTrail.ToListAsync();

            //Build the CSV file data as a Comma separated string.
            string csv = string.Empty;

            foreach (string columnName in columnNames)
            {
                //Add the Header row for CSV file.
                csv += columnName + ',';
            }

            //Add new line.
            csv += "\r\n";

            foreach (var at in auditTrails)
            {
                //Add the Data rows.
                csv += at.Id.ToString().Replace(",", ";") + ',';
                csv += at.OldData.Replace(",", ";") + ',';
                csv += at.NewData.Replace(",", ";") + ',';
                csv += at.ActionModuleId.Replace(",", ";") + ',';
                csv += at.ActionTypeId.Replace(",", ";") + ',';
                csv += at.CompanyId.ToString().Replace(",", ";") + ',';
                csv += at.ObjectId.ToString().Replace(",", ";") + ',';
                csv += at.CreatedDatetime.ToString().Replace(",", ";") + ',';
                csv += at.UserId.Replace(",", ";") + ',';

                //Add new line.
                csv += "\r\n";
            }

            var file = "AuditTrail.csv";

            //Download the CSV file.
            byte[] bytes = Encoding.ASCII.GetBytes(csv);
            return(File(bytes, "application/text", file));
        }
Example #6
0
        public async Task <FileResult> Export()
        {
            string[] names = typeof(MasterAssetModel).GetProperties().Select(property => property.Name).ToArray();

            string[] columnNames = new string[] { "Code", "Name", "Remark", "Status" };

            MasterAssetModel entities = new MasterAssetModel();

            var customers = await _context.MasterAssetModel.ToListAsync();

            //Build the CSV file data as a Comma separated string.
            string csv = string.Empty;

            foreach (string columnName in columnNames)
            {
                //Add the Header row for CSV file.
                csv += columnName + ',';
            }

            //remove symbol "," behind
            csv = csv.Remove(csv.Length - 1, 1);

            //Add new line.
            csv += "\r\n";

            foreach (var customer in customers)
            {
                //Add the Data rows.
                csv += customer.Code.Replace(",", ";") + ',';
                csv += customer.Name.Replace(",", ";") + ',';
                if (customer.Remark != null)
                {
                    csv += customer.Remark.Replace(",", ";") + ',';
                }
                else
                {
                    customer.Remark = "";
                    csv            += customer.Remark.Replace(",", ";") + ',';
                }

                if (customer.Status != false)
                {
                    string Status = "YES";
                    csv += Status.Replace(",", ";");
                }
                if (customer.Status != true)
                {
                    string Status = "NO";
                    csv += Status.Replace(",", ";");
                }

                //Add new line.
                csv += "\r\n";
            }

            var file = "AssetModelMaster.csv";

            //Download the CSV file.
            byte[] bytes = Encoding.ASCII.GetBytes(csv);
            return(File(bytes, "application/text", file));
        }