Пример #1
0
        public async Task <IHttpActionResult> UpdateOriginalManufacturer([FromBody] OriginalManufacturerList value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (TransactionScope scope = new TransactionScope())
                using (var connection = new SqlConnection(sqlConnectionString))
                {
                    connection.Open();

                    var orgManufacturer = new OriginalManufacturerList()
                    {
                        Address     = value.Address,
                        ContactNo   = value.ContactNo,
                        IsActivated = value.IsActivated,
                        Name        = value.Name,
                        Id          = value.Id
                    };

                    string updateQuery = @"UPDATE OriginalManufacture SET Address = @Address,ContactNo=@ContactNo,IsActivated = @IsActivated, Name= @Name WHERE Id = @Id";

                    var result = connection.Execute(updateQuery, orgManufacturer);
                    scope.Complete();
                    return(Json(new { Message = "Record Updated Successfully" }));
                }
        }
Пример #2
0
        public async Task <IHttpActionResult> AddOriginalManufacturer([FromBody] OriginalManufacturerList value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (var connection = new SqlConnection(sqlConnectionString))
            {
                connection.Open();

                var CommandExist = connection.Query <OriginalManufacturerList>("Select * from Supplier where Name = @Name", new { Name = value.Name }).FirstOrDefault();
                if (CommandExist == null)
                {
                    var p = new SupplierList
                    {
                        Name        = value.Name,
                        Address     = value.Address,
                        ContactNo   = value.ContactNo,
                        IsActivated = value.IsActivated
                    };
                    p.Id = connection.Query <int>(@"insert OriginalManufacture(Name,Address,ContactNo,IsActivated) values (@Name,@Address,@ContactNo,@IsActivated) select cast(scope_identity() as int)", p).First();

                    return(Json(new { Message = "Record Inserted Successfully" }));
                }
                else
                {
                    throw new ProcessException("Formation already exists");
                }
            }
        }
Пример #3
0
        public dynamic GetByOriginalManufacturerId(int Id)
        {
            var orgManufacturer = new OriginalManufacturerList();
            var connection      = new SqlConnection(sqlConnectionString);

            orgManufacturer = connection.Query <OriginalManufacturerList>("Select * from OriginalManufacture where Id = @Id", new { Id = Id }).FirstOrDefault();
            return(orgManufacturer);
        }